freeaiapi.ai

Anthropic Messages format

Call models with the Anthropic Messages API format.

Besides the OpenAI format, the API serves the Anthropic Messages format at /v1/messages. This lets Anthropic SDKs and tools built on them (such as Claude Code) work with freeaiapi.ai.

curl https://api.freeaiapi.ai/v1/messages \
  -H "x-api-key: $FREEAIAPI_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-3-5-sonnet-20241022",
    "max_tokens": 512,
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

With the Anthropic Python SDK, set the base URL to the API root (the SDK adds /v1/messages itself):

from anthropic import Anthropic

client = Anthropic(base_url="https://api.freeaiapi.ai", api_key="YOUR_FREEAIAPI_KEY")
message = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=512,
    messages=[{"role": "user", "content": "Hello!"}],
)
print(message.content[0].text)