Docs · Claude Code

How do I connect Claude Code to FreeModel? Two setups, different results

最后更新:

FreeModel is an AI model gateway: one key for 200+ models across dozens of providers, routed by task with free capacity tried first. Claude Code can use FreeModel as a tool it calls, or as the thing that answers everything. Pick based on what you actually want to move.

Which one you want

QuestionMCP serverBase URL
What changesClaude Code gains a tool that routes a task to another modelEvery request Claude Code makes goes to FreeModel
Who answers normallyClaude, as beforeWhichever model the router picks
Good forKeeping Claude's behaviour, but sending some work elsewhereCutting cost or switching model without changing how you work
Config file~/.claude/mcp.jsonEnvironment or ~/.claude/settings.json
Reversible byDeleting the MCP entryUnsetting one variable

If you are unsure: start with the MCP server. It is the setup the package ships for, and it does not change what happens when you do not invoke the tool.

Setup A: MCP server

The package runs as a local MCP server. Claude Code launches it, and it exposes four tools: browse the catalogue, read your tiers and account, and send one prompt.

{
  "mcpServers": {
    "freemodel": {
      "command": "npx",
      "args": ["-y", "freemodel-mcp"],
      "env": {
        "FREEMODEL_KEY": "sk-your-key"
      }
    }
  }
}

Restart Claude Code after saving. The server appears in the MCP list; if it does not, run npx -y freemodel-mcp by hand once to see whether it starts at all — that separates a config problem from a network one.

The four tools are freemodel_models (public — it works with no key at all), freemodel_tiers, freemodel_account and freemodel_chat. FREEMODEL_API is optional and defaults to https://freemodel.online/v1; set it only to point the server at another deployment.

Setup B: send everything through FreeModel

If you want Claude Code's own requests routed rather than just gaining a tool, point its Anthropic base URL at FreeModel:

export ANTHROPIC_BASE_URL="https://freemodel.online/api/gateway"
export ANTHROPIC_API_KEY="sk-your-key"

The base is the gateway root, not the gateway root plus /v1. Claude Code appends /v1/messages itself; adding /v1 here gives you /v1/v1/messages and a 404.

This changes who answers. Everything Claude Code sends, including tool-use turns, goes through the router, and the router picks the model. To undo it, unset the variable.

Checking it works

Before blaming the client, check the two things it depends on. The model list is public, so this needs no key at all:

# 1. is the gateway reachable and does it serve models?
curl -s https://freemodel.online/v1/models | grep -o '"id"' | wc -l

# 2. is the Anthropic-shaped endpoint there? 401 means yes, key required
curl -s -o /dev/null -w "%{http_code}\n" \
  -X POST https://freemodel.online/api/gateway/v1/messages \
  -H "Content-Type: application/json" -d '{}'

A 401 on the second command is the answer you want. It means the endpoint exists and is waiting for a valid key. A 404 means the path is wrong.

Common problems

SymptomCause
MCP server not listedBad JSON in mcp.json, or npx is not on PATH for the GUI process
Server listed, tool errorsWrong FREEMODEL_KEY, or FREEMODEL_API points at something other than the API root
404 from every requestBase URL has /v1 in it when it should not
401 from every requestKey missing the sk- prefix, or the environment variable is not exported in the shell that launched the client
Worked in one terminal, not anotherexport only affects the shell it ran in. Check ~/.claude/settings.json if you want it everywhere

Next

Doing it in three steps

Pick the setup first, because the two write to different places. Everything after that is one edit and a restart.

  1. Step 1: Decide what you are moving. If Claude should keep answering and only some work should go elsewhere, use the MCP server. If every request should be routed, use the base URL.
  2. Step 2: Write the value where Claude Code reads it. The MCP setup goes in ~/.claude/mcp.json under mcpServers. The base URL setup goes in the environment, or in the env block of ~/.claude/settings.json, as ANTHROPIC_BASE_URL plus ANTHROPIC_API_KEY.
  3. Step 3: Restart Claude Code and confirm. With the MCP setup the server appears in the MCP list; with the base URL setup any request that comes back has already been through the router.

Pick one, not both. Running them together routes Claude Code's own requests through FreeModel and also hands it a tool that routes further work, a setup that is harder to reason about than either half alone.

What the router is choosing from

With the base URL setup, the model that answers is whichever one the router lands on. That is only a problem if the catalogue behind it is thin, and it is not: the 199 listed models put chat, image, video, speech and embeddings in one list, and 77% of them are chat models[1]. Every turn, including the tool-use turns that read a file or write a patch, is re-decided per request rather than pinned to one model.

For chat there is a second way to hand the choice over: three subscription tier aliases, fm-v1-lite, fm-v1-standard and fm-v1-pro. Name one instead of a concrete id and the router re-resolves it on every call, so a provider that starts failing loses the next request rather than the whole turn. That is the trade the aliases exist for: no stable model name, but nowhere for a dead provider to strand the run.

Claude Code FAQ

Does the MCP setup change who answers my normal requests?
No. Claude Code keeps talking to whatever it talked to before, and the package only adds a tool that routes the work you explicitly hand it. The base URL setup is the one that changes the answer to everything.
Can I point the base URL here and keep using an Anthropic key?
No. The two variables travel together: ANTHROPIC_BASE_URL moves the destination, and ANTHROPIC_API_KEY is the key that destination checks. With the base pointed here, that key has to be a FreeModel sk- key, and an Anthropic key will come back as a 401.
What happens to tool-use turns when the router picks the model?
They go through the same endpoint as any other turn, and the router re-decides per request, so a provider that fails is skipped rather than returning an error — but a model that fails mid-task is more visible here than in a plain chat, because every later step depends on the earlier result.
How do I undo either setup?
Delete the freemodel entry from ~/.claude/mcp.json, or unset ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY in whichever place you set them. Nothing on the FreeModel side needs cleaning up — no resource is created per client.
Do I still need the MCP package if I am using the base URL?
No. The MCP server is an alternative to the base URL, not a companion to it, and a setup that uses both routes one task to a second model while the main turn is already being routed. Keep the MCP route when you want Claude's behaviour intact.

Sources

Every third-party figure quoted on this site was read from the vendor documentation linked below, on the date stated. None of these links are affiliate links and none of these vendors paid to be listed. If a number here disagrees with the page it came from, the page is right — tell us and it gets corrected.

Where the percentages come from

Every share quoted on this site is counted from the live model list, not estimated. Divide the two counts in the last column, round to the nearest whole percent, and you get the number in the first.

ShareOf whatCount
77%are chat models153 of 199 listed entries
9%generate images18 of 199 listed entries
23%are not chat models46 of 199 listed entries
3%are modality routes6 of 199 listed entries
17%carry a context length34 of 199 listed entries

[1] Counted on 29 September 2026 from GET https://freemodel.online/v1/models, which needs no key and no account. Every row uses all 199 listed entries as the denominator, because the only thing the endpoint states for every entry is its modality. It no longer publishes per-model capability flags such as tool calling or reasoning, so this site quotes no shares for them. Fetch the list and recount whenever you want to check the arithmetic.