ย้ายจาก Anthropic API
ชี้ Anthropic SDK มาที่ ai.ml: /v1/messages รองรับ Messages API รวมถึงการสตรีม เครื่องมือ thinking และ prompt caching และกำหนดเส้นทางไปยัง Anthropic โดยตรงหรือไปยังโมเดลอื่นใดก็ได้
ก่อน
import anthropic
client = anthropic.Anthropic(api_key="sk-ant-…")
client.messages.create(model="claude-sonnet-4-5", max_tokens=1024, messages=msgs)หลัง
import anthropic
client = anthropic.Anthropic(base_url="https://api.ai.ml", api_key="aiml-live-…")
client.messages.create(model="anthropic/claude-sonnet-4.5", max_tokens=1024, messages=msgs)เฮดเดอร์
| Anthropic | ai.ml |
|---|---|
| x-api-key: sk-ant-… | x-api-key: aiml-live-… (หรือ Authorization: Bearer) |
| anthropic-version | คงไว้ aiml-version (ไม่บังคับ) กำหนดเวอร์ชันของ IR |
| anthropic-beta | ส่งต่อเมื่อผู้ให้บริการคือ Anthropic |
อะไรเปลี่ยน อะไรไม่เปลี่ยน
- เฮดเดอร์ x-api-key และ anthropic-version ใช้ได้ตามเดิม เวอร์ชันนั้นกำหนดรูปแบบ wire ส่วน aiml-version กำหนดรูปแบบของเรา
- บล็อก thinking พร้อมลายเซ็นส่งไปกลับกับ Anthropic ได้ครบถ้วน ผู้ให้บริการอื่นจะได้รับงบประมาณการให้เหตุผลที่เทียบเท่าหากรองรับ
- ขอใช้โมเดลที่ไม่ใช่ Anthropic ผ่านเอนด์พอยต์เดียวกันได้ (model: deepseek/deepseek-v3.2): เครื่องมือและ JSON schema จะถูกแปลง ฟีเจอร์ที่ไม่รองรับจะส่งกลับเป็นคำเตือนแทนที่จะถูกตัดทิ้งเงียบๆ
- 529 / overloaded จาก Anthropic จะลองใหม่บนโฮสต์ Anthropic อื่น หรือ failover ตามนโยบายของคุณ