POST /v1/messages endpoint. Code written for the Anthropic SDK’s client.messages.create(...) works after changing the base_url and api_key, and it can call any model the Swarms API supports, not only Claude models.
The endpoint is non-streaming and text-only. It runs through the same path as /v1/chat/completions, so model routing, billing, rate limits and logging are the same.
Endpoint Information
- URL:
/v1/messages - Method:
POST - Authentication: Required (
x-api-keyheader, which the Anthropic SDK sends fromapi_key;Authorization: Bearer <key>also works). Theanthropic-versionheader is accepted and ignored - Rate Limiting: Subject to tier-based rate limits
- API reference: Messages (Anthropic-compatible)
Quick Start
- Python
- cURL
The SDK’s
base_url is https://api.swarms.world, without /v1: the Anthropic SDK adds /v1/messages itself. The OpenAI SDK’s base_url includes /v1.Request Fields
Not Supported Yet
These return 400 with"Not supported yet: <names>", or a message naming the problem:
stream: true- Image, document and any other non-
textcontent blocks toolsthinkingstop_sequences- Assistant prefill:
messagesthat end on anassistantturn - Any other field not listed above, when set to a non-empty value
Response Fields
Errors
Errors from this endpoint use the Anthropic error shape, so the Anthropic SDK’s exception classes work:
A missing or invalid API key (401), and a purchased credit balance at or below $1.00 (402), are rejected by the authentication layer before the request reaches this endpoint. Those bodies use the Swarms shape instead,
{"error": {"type": "authentication_error" | "insufficient_credits", "message": ..., "detail": ..., "status_code": ...}}. The Anthropic SDK still raises AuthenticationError or an APIStatusError for them by status code.
Billing
Billing, rate limits and the minimum balance are the same as/v1/chat/completions: the provider-reported input and output tokens at the model’s price plus a 15% service fee, deducted after the run. The endpoint is billable, so it needs a purchased credit balance above $1.00. See Pricing.
Related
- OpenAI-Compatible Endpoint —
POST /v1/chat/completions, with streaming and tool calling - Responses API —
POST /v1/responsesfor the OpenAI SDK’sclient.responses.create