Skip to content
Main Site News Console

Claude Native Format

In addition to the OpenAI-compatible interface, 4ALL API also supports the Anthropic native Messages protocol, which is suitable for applications already built on the Anthropic SDK, enabling zero-change migration (such as Claude Code).

POST https://api.4allapi.com/v1/messages

Request Example

Terminal window
curl https://api.4allapi.com/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: $AIPROXY_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "fable-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Explain quantum entanglement"}]
}'

Key points:

  • Authentication uses the x-api-key header (also compatible with Authorization: Bearer);
  • max_tokens is required in the native protocol;
  • Streaming is also supported; just set "stream": true, and the event format follows the Anthropic SSE specification;
  • Use the top-level system field for system prompts, rather than the messages array.

Anthropic SDK

import anthropic
client = anthropic.Anthropic(
base_url="https://api.4allapi.com",
api_key="sk-你的密钥",
)
msg = client.messages.create(
model="fable-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Explain quantum entanglement"}],
)
print(msg.content[0].text)