Messages

The Anthropic Messages format, used by Claude Code.

Creates a message in the Anthropic Messages format, the format Claude Code uses. Works with the official Anthropic SDKs.

Method and path

POST/v1/messages

Anthropic SDKs take the base URL https://api.relayvia.dev. Send the key as x-api-key: sk-... or Authorization: Bearer sk-..., together with the anthropic-version header your SDK already sends.

Common parameters

ParameterTypeRequiredDescription
modelstringYesOfficial model name.
max_tokensintegerYesOutput limit (required); it decides how much is reserved before the call.
messagesarrayYesThe conversation: user and assistant turns with text, image and document content.
systemstring | arrayNoSystem prompt.
streambooleanNotrue to receive Server-Sent Events.
toolsarrayNoTools your code runs: no type, or type: custom.
tool_choiceobjectNoWhether the model must, may or must not call a tool.
thinkingobjectNoExtended thinking settings.
metadataobjectNouser_id for abuse tracking.

Requests are forwarded in the original format, so the original API's parameters work unless the next section says otherwise. This table lists the common ones; see the official reference for the rest.

Differences from the original API

  • tools[] only accepts tools your code runs: no type, or type: custom. Server tools (web fetch, code execution and similar) and mcp_servers return 400 unsupported_parameter.
  • Web search is not available. web_search_* tools are removed and the request runs without search. If web search is the only tool, as in Claude Code's WebSearch requests, or tool_choice names it, the request returns 400.
  • Files from the Files API (source.type: file) and documents by URL (source.type: url) return 400 unsupported_parameter; send them as base64.
  • anthropic-beta values Relayvia does not support are dropped without an error; the rest are forwarded.
  • Message Batches (/v1/messages/batches) are not provided and return 400.
  • metadata.user_id is scoped to your account before forwarding, so it is never shared with other accounts.
  • Events are forwarded as they arrive, and message_delta carries the final output usage. A : keepalive comment is sent after every 15 seconds without data. message.model shows the name you sent.
  • A non-streaming request with no response within 95 seconds returns 500 upstream_timeout; use streaming for long outputs. Or send the header X-Robi-Keepalive: 1: if there is no response within 30 seconds you get a 200 right away and a space every 15 seconds until the JSON arrives, and a later failure arrives as an error object in the body.

Request examples

cURL
curl https://api.relayvia.dev/v1/messages \
  -H "x-api-key: sk-..." \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{"model":"claude-opus-5","max_tokens":1024,"messages":[{"role":"user","content":"Hello!"}]}'

Response and streaming examples

Response
{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "model": "claude-opus-5",
  "content": [
    {
      "type": "text",
      "text": "Hello! How can I help?"
    }
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 9,
    "output_tokens": 8
  }
}

Errors this endpoint returns

HTTPcodeWhen
400invalid_requestA parameter is invalid. If the model rejected it, the message is this sentence, or Invalid value for parameter <param>. with param set.
400unsupported_parameterThe request uses something Relayvia does not offer: stored server-side state, a hosted tool or a remote file. param names it.
400invalid_mediaThe model reports that an input image or file format is not supported.
400media_unreachableThe model could not read the media URL you sent.
400content_policyThe input did not pass the model's safety review. If the model does not say whether the input or the output was refused, the message is Content did not pass safety review.
400content_policy_outputThe model generated a result, but the result did not pass safety review. Your input was not the problem.
401invalid_api_keyThe API key does not exist, is disabled or has expired.
402insufficient_quotaNot enough credits: the account's credits, the key's limit, the team member's limit or an account spend limit cannot cover the request, or the account is frozen.
403forbiddenThe key may not use this model, the source IP is not on the allowlist, or the account is disabled.
404model_not_foundThe model is not listed.
413request_too_largeThe request body is over 20 MB, or the model reports that the input exceeds its context or size limit (then with this sentence).
429rate_limitedToo many requests: per IP, per key, per account, or too many requests in progress at once.
500model_price_errorThe model has no price yet, so it cannot be called.
500upstream_errorRelayvia tried other model services and every attempt failed.
503no_available_channelNo model service is available for this model right now.
503service_busyEvery model service for this model reported being busy.
500upstream_timeoutEvery attempt timed out.

Every code, its fixed message and what to do are on the error codes page.