Anthropic Messages API
The Anthropic request format, so the Anthropic SDKs, Claude Code and Claude Desktop work with your FreeModel key.
Endpoints
| Method | Path | Purpose |
|---|---|---|
| POST | https://freemodel.in/v1/messages | Create a message (streamed or not) |
| POST | https://freemodel.in/v1/messages/count_tokens | Estimate the input tokens of a request |
The base URL for Anthropic clients is https://freemodel.in; the client adds /v1/messages itself. A base URL of https://freemodel.in/v1 also works.
Authenticate with x-api-key: fm_… (what Anthropic SDKs send), Authorization: Bearer fm_… or anthropic-api-key: fm_…. The key needs the inference scope. The anthropic-version header may be sent; it is not required.
Any listed model can be called through this endpoint. Claude models other than Claude Haiku 5.5 need a paid plan; a free account can use the free models such as claude-haiku-5.5 or gpt-6-luna here too.
Examples
curl https://freemodel.in/v1/messages \
-H "x-api-key: fm_your_key_here" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5",
"max_tokens": 1024,
"system": "You are a concise assistant.",
"messages": [{"role": "user", "content": "Explain HTTP 402 in one sentence."}]
}'
The example uses claude-sonnet-5, which needs a paid plan. On the free plan, change the model to claude-haiku-5.5 or gpt-6-luna.
import anthropic
client = anthropic.Anthropic(api_key="fm_your_key_here", base_url="https://freemodel.in")
msg = client.messages.create(
model="claude-sonnet-5", # paid plan; use "claude-haiku-5.5" on the free plan
max_tokens=1024,
messages=[{"role": "user", "content": "Explain HTTP 402 in one sentence."}],
)
print(msg.content[0].text)
Request fields
| Field | Type | Notes |
|---|---|---|
model | string | Required. A listed model id. |
messages | array | Required, not empty. Roles user and assistant. |
max_tokens | int | Default 4,096. Kept between 16 and 32,768 (up to 64,000 with thinking on). |
system | string or array | System prompt, as a string or text blocks. |
stream | bool | Stream server-sent events. |
temperature | number | Clamped to 0–2. |
top_p | number | Clamped to 0–1. |
stop_sequences | array | Strings that end the answer. |
tools | array | Tool definitions with name, description, input_schema. |
tool_choice | object | Includes disable_parallel_tool_use. |
thinking | object | {"type": "enabled", "budget_tokens": N} or {"type": "adaptive"}. Budget at least 1,024; default 16,000. With thinking on, max_tokens is raised to at least budget + 2,048. |
Content blocks
| Block | Handling |
|---|---|
text | Sent as text. |
image | Base64 (source.type: "base64") or URL source. Needs a vision model. |
document | Base64 PDFs: the text is extracted and sent. Base64 text/* files and text sources are sent as text. URL documents are passed only as a reference to the URL. |
tool_use / tool_result | Tool calls and their results, matched by id. Images inside a tool result are kept; is_error is marked. |
thinking, redacted_thinking | Earlier thinking blocks you send back are not passed on. |
No JSON-mode field is read on this endpoint. For structured output, use a tool, or see Structured output for the formats that support it.
Response
{
"id": "msg_01AbCdEfGhIjKlMnOpQrStUv",
"type": "message",
"role": "assistant",
"model": "claude-sonnet-5",
"content": [{"type": "text", "text": "HTTP 402 means payment is required before the request can be served."}],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 28,
"output_tokens": 16,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 0
}
}
stop_reason is end_turn, max_tokens, tool_use or refusal. With thinking on, the answer can include thinking blocks. Responses carry a request-id header; quote it when you contact support.
Streaming
With "stream": true you get the Anthropic event sequence: message_start, then content_block_start / content_block_delta / content_block_stop for each block, then message_delta (with stop_reason and final usage) and message_stop.
with client.messages.stream(
model="gpt-6-luna",
max_tokens=512,
messages=[{"role": "user", "content": "Count to five."}],
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
count_tokens
curl https://freemodel.in/v1/messages/count_tokens \
-H "x-api-key: fm_your_key_here" \
-H "Content-Type: application/json" \
-d '{"model": "claude-sonnet-5", "messages": [{"role": "user", "content": "Hello"}]}'
{ "input_tokens": 2 }
The number is an estimate from the length of system and messages (about 3.8 characters per token). Tool definitions are not included. The call is not charged. The real count of a request is in its usage.
Claude Code
export ANTHROPIC_BASE_URL=https://freemodel.in
export ANTHROPIC_AUTH_TOKEN=fm_your_key_here
export ANTHROPIC_MODEL=claude-sonnet-5
export ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-5-5
claude
Claude Code also uses a background model; it must be a listed model too, hence ANTHROPIC_DEFAULT_HAIKU_MODEL. Claude models other than Claude Haiku 5.5 need a paid plan. More tools are covered in Using coding agents.
Errors
This endpoint answers in the Anthropic error shape ({"type":"error","error":{"type":…,"message":…}}). A 503 is sent as 529 overloaded_error, and 429 and 529 responses include Retry-After: 3 and retry-after-ms: 3000, so the SDK's own retry works. Out of tokens is 402 billing_error; an unlisted model is 404 not_found_error. Missing model or messages, or a body that is not JSON, is 400 invalid_request_error. The full list is on Errors and status codes.