SupaNexus

Messages (Anthropic)

Markdown version

Replace <BASE_URL> using values from Endpoints.

Create a model response using the Anthropic Messages API format — similar to OpenRouter /v1/messages.

POST <BASE_URL>/v1/messages

Use this endpoint when integrating Anthropic SDK, Claude Code, or other clients that expect native Anthropic shapes. Non-Anthropic upstreams are translated to OpenAI Chat Completions. Prefer this endpoint for Claude images.

Authentication

Required: Authorization: Bearer <API_KEY> (same SupaNexus API key as /v1/chat/completions).

Request headers

HeaderRequiredDescription
AuthorizationYesBearer API Key
Content-TypeYesapplication/json
Idempotency-KeyNoDeduplicate within 24h per API key
Accept-Language / X-LocaleNoLocalized error text where applicable

Request body

SupaNexus accepts standard Anthropic Messages JSON and reads model and stream.

{
  "model": "anthropic/claude-3-5-sonnet",
  "max_tokens": 1024,
  "messages": [
    {"role": "user", "content": "Hello!"}
  ],
  "stream": false
}
FieldRequiredDescription
modelYesModel id from GET /v1/models
messagesYesAnthropic message array
max_tokensYesMaximum output tokens (Anthropic requirement)
systemNoSystem prompt (string or content blocks)
streamNotrue for Anthropic SSE events
temperature, top_p, stop_sequencesNoPassed through when supported
tools, tool_choice, thinking, metadataNoPassed through in Anthropic-compatible form when supported

Multimodal input (images)

When the model’s architecture.input_modalities includes "image", messages[].content may be a content-block array carrying both text and images.

Base64 image example

{
  "model": "anthropic/claude-sonnet-5",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "image",
          "source": {
            "type": "base64",
            "media_type": "image/jpeg",
            "data": "/9j/4AAQSkZJRg..."
          }
        },
        {"type": "text", "text": "Describe this image"}
      ]
    }
  ]
}

URL image example

{
  "type": "image",
  "source": {
    "type": "url",
    "url": "https://example.com/photo.jpg"
  }
}

Limitation: OpenAI-protocol upstream models

If the target model’s upstream uses the OpenAI Chat Completions protocol (not anthropic/*), Anthropic image blocks are not converted to image_url, and the upstream typically rejects the request. Use POST /v1/chat/completions with OpenAI image_url instead — see Parameters → Multimodal input.

Rule of thumb: for images, keep the client protocol aligned with the model’s upstream — use this endpoint for anthropic/*, and /v1/chat/completions for other models.

Non-streaming response

Anthropic-shaped JSON:

{
  "id": "msg_...",
  "type": "message",
  "role": "assistant",
  "model": "claude-3-5-sonnet-20241022",
  "content": [{"type": "text", "text": "Hello! How can I help?"}],
  "stop_reason": "end_turn",
  "usage": {"input_tokens": 12, "output_tokens": 8}
}

Streaming

When stream: true, SupaNexus returns Anthropic event-stream (message_start, content_block_delta, message_delta, message_stop). See Streaming for general SSE notes.

Response headers (SupaNexus)

Same as Chat Completions: X-SNX-Trace-ID, X-SNX-Model, X-SNX-Provider.

Error format

On /v1/messages, SupaNexus returns Anthropic-style errors (not OpenRouter numeric error.code):

{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "you must provide a model parameter"
  }
}
HTTPTypical error.type
400invalid_request_error
401authentication_error
402billing_error
404not_found_error
429rate_limit_error
503overloaded_error

For OpenRouter-shaped errors, use POST /v1/chat/completions instead.

OpenAI vs Anthropic endpoints

ClientEndpointError body
OpenAI SDKPOST /v1/chat/completionsOpenRouter {error:{code,message}}
Anthropic SDK / Claude CodePOST /v1/messagesAnthropic {type,error:{type,message}}

Both use the same SupaNexus API key and share routing, quota, and billing.

Related