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/messagesRequest Example
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-keyheader (also compatible withAuthorization: Bearer); max_tokensis 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
systemfield forsystemprompts, 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)