Skip to content
Auto
English

Anthropic Messages

POST https://api.relyven.com/v1/messages
Terminal window
curl https://api.relyven.com/v1/messages \
-H "x-api-key: $RELYVEN_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "YOUR_CLAUDE_MODEL_ID",
"max_tokens": 256,
"messages": [{"role":"user","content":"Reply with OK."}]
}'

max_tokens is required by the Messages API. The selected model must be within the key’s allowed scope.

Messages uses a top-level system field. Do not add a role: "system" entry to the messages array:

{
"model": "YOUR_CLAUDE_MODEL_ID",
"max_tokens": 256,
"system": "Answer concisely.",
"messages": [{"role":"user","content":"Explain health checks."}]
}

Relyven does not intentionally inject or override the system prompt.

Set "stream": true to receive SSE. Handle Anthropic event types such as message_start, content_block_delta, message_delta, and message_stop; do not parse them as OpenAI streaming chunks.

Declare tools and their input schemas in tools. When Claude returns a tool_use content block, execute the tool and send a matching tool_result in a later user message.

{
"name": "get_weather",
"description": "Get weather for a city",
"input_schema": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}

Always validate model-generated tool arguments. Add confirmation and idempotency controls for operations with side effects.

Models with prompt-caching support can accept cache_control on system, message content, tool definitions, and other supported blocks. Availability, minimum cacheable content, and billing depend on the model and model provider.

Relyven does not intentionally remove cache_control; this does not imply identical caching support across every Claude model.

Models that provide the capability can accept a thinking configuration. Its constraints interact with max_tokens, tool use, and model versions; follow Anthropic’s requirements for the selected model.

Relyven does not intentionally change thinking or reduce its configured level. Unsupported combinations may still return a model-provider 400.

  • 400: check max_tokens, top-level system, content blocks, and model capabilities.
  • 401/403: check x-api-key, model permission, and the base URL.
  • Stream parsing failure: use Anthropic SSE event types, not OpenAI chunk shapes.
  • Broken tool loop: verify that tool_use.id matches tool_result.tool_use_id.

Official references: Messages API · Streaming · Tool use · Prompt caching · Extended thinking