Migrate
From Anthropic
Keep the Anthropic SDK; change the base URL, the key and the model id.
The three changes
- Base URL
https://api.anthropic.combecomeshttps://api.ai.ml(no/v1: the SDK appends it). - Key
sk-ant-…becomesaiml-live-…. - Model
claude-sonnet-4.6becomesanthropic/claude-sonnet-4.6. Bare Anthropic model names are accepted and resolve toanthropic/<name>.
import anthropic
client = anthropic.Anthropic(base_url=os.environ.get("AIML_BASE_URL", "https://api.ai.ml"), api_key=os.environ["AIML_API_KEY"])What stays the same
- The Messages request:
system,messageswith content blocks,toolswithinput_schema,tool_choice,thinking,stop_sequences,metadata.user_id,cache_controlon blocks. - Streaming events:
message_start,content_block_start/delta/stop,message_delta,message_stop,ping. - The error envelope
{"type":"error","error":{"type","message"}};error.codeadds the aiml code.
What is different
| Topic | Anthropic | aiml |
|---|---|---|
anthropic-version header | required | accepted and ignored; use aiml-version |
| Request id | request-id header | x-aiml-request-id header and the message id |
| Cost | not returned | aiml.cost.total_micro_usd in the body, x-aiml-cost-micro header |
529 overloaded_error | Anthropic capacity | 503 with code upstream_capacity; the gateway has usually already tried another endpoint |
| Billing | postpaid | prepaid credits; 402 when the balance cannot cover the reserve |
Thinking and signatures
Thinking blocks are replayed to Anthropic only when they carry the signature Anthropic issued; unsigned or foreign thinking blocks are dropped with a provider_block_dropped warning rather than rejected. When thinking is enabled, Anthropic forbids temperature, top_p and top_k; the gateway drops them with a warning instead of failing the call.
Calling non-Anthropic models
The Messages route is a dialect, not a vendor lock: model: "openai/gpt-5-mini" works. Parameters the target cannot express produce x-aiml-warnings; features that would change the result (for example a server tool the target lacks) return 422 unsupported_feature.<name>.