Skip to main content
The Swarms API exposes an Anthropic Messages API-compatible 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-key header, which the Anthropic SDK sends from api_key; Authorization: Bearer <key> also works). The anthropic-version header is accepted and ignored
  • Rate Limiting: Subject to tier-based rate limits
  • API reference: Messages (Anthropic-compatible)

Quick Start

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.
Response:

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-text content blocks
  • tools
  • thinking
  • stop_sequences
  • Assistant prefill: messages that end on an assistant turn
  • 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.