B2BB2B LLM

POST /v1/messages

Anthropic-compatible Messages API with aliases, streaming, tools, vision, caching, and thinking.

POST /v1/messages

Authentication

x-api-key: mg_live_...
anthropic-version: 2023-06-01
content-type: application/json

Bearer authentication is also accepted.

Request

curl https://api.model-gate.com/v1/messages \
  -H "x-api-key: mg_live_..." \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-4.6",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Write a short release note."}
    ]
  }'

Response

{
  "id": "msg_example",
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-4.6",
  "content": [{"type": "text", "text": "This release improves documentation and model routing."}],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 11,
    "output_tokens": 9,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0
  }
}

Streaming

Add "stream": true. Model Gate forwards Anthropic-compatible SSE events and records the final token usage for settlement.

Aliases and accounting

If an alias is supplied, it is replaced with the canonical model before the request is queued or sent upstream. Pricing, usage cost, request history, and model restrictions use the canonical model.

StatusMeaningAction
400Invalid requestCheck the request body and model ID.
401Invalid or frozen keyVerify or rotate the API key.
429Rate or concurrency limit exceededRespect Retry-After and retry with backoff.
5xxTemporary upstream or gateway errorRetry idempotent requests with exponential backoff.