Skip to main content
Sign in

Website navigation

API referenceMessages

Messages

Anthropic Messages compatibility for Claude Code and the Anthropic SDKs. Supply max_tokens and put system instructions in the top-level system field.

POSThttps://api.saveapi.cc/v1/messages
On this page

Request example

Set the Anthropic SDK base URL to https://api.saveapi.cc. The SDK appends /v1/messages. For raw HTTP, /v1/messages and /messages are equivalent.

Example language
curl -sS "https://api.saveapi.cc/v1/messages" \
  -H "x-api-key: $AI_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "claude-sonnet-5-5",
  "max_tokens": 256,
  "system": "You are a helpful assistant.",
  "messages": [
    {
      "role": "user",
      "content": "Hello"
    }
  ]
}'

Headers

x-api-keyYOUR_API_KEYRequired
Use your platform API key. You can also send Authorization: Bearer YOUR_API_KEY.
anthropic-version2023-06-01
Select the Anthropic API version. The default is 2023-06-01.
anthropic-betastring
Enable Anthropic beta features supported by the selected model.
Content-Typeapplication/json
The request body is JSON.

Request parameters

This list covers common request fields. Optional settings depend on the selected model and API format.

modelstringRequired
Match a data[].id from GET /v1/models exactly. An unavailable model returns 404 model_not_found.
max_tokensintegerRequired
Set an output limit from 1 to 32768. A missing value returns 400 invalid_request_error.
messagesarrayRequired
Send user and assistant messages in order. Use content for text, text blocks, tool calls, and tool results. For each tool_use, put a tool_result with the matching tool_use_id in the next user message’s content.
systemstring | array
Set top-level system instructions as a string or an array of text blocks.
thinkingobject
Configure extended thinking on compatible models. Some Claude models use adaptive mode and read the effort from output_config.effort.
cache_controlobject
Add prompt cache breakpoints to supported content blocks in system or messages, for example at the end of system or in the last message.
streamboolean
Set true to receive server-sent events. Omit for JSON.
toolsarray
Declare client-executed tools and control their selection with tool_choice.
temperaturenumber
Control sampling randomness. The availability and range of temperature and top_p depend on the model.
stop_sequencesarray
Set sequences that stop generation on supported models.

How SaveAPI handles requests

  • Use this endpoint for supported extended thinking and prompt caching on Claude. For other text models, available options depend on the selected model.
  • Only stateless text input is supported; image, audio, video and PDF inputs return 400.

JSON response

Join the text blocks in content. stop_reason can indicate completion (end_turn), the output limit (max_tokens), or a tool call (tool_use). usage includes input_tokens and output_tokens, plus cache counts when available.

JSON
{
  "id": "msg_example",
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-5-5",
  "content": [
    {
      "type": "text",
      "text": "Hello!"
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 7,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0,
    "output_tokens": 4
  }
}
  • Include the x-request-id response header when reporting an issue, if available. It identifies the request on this platform.
  • For Claude, input_tokens excludes cached tokens. Cache writes appear in cache_creation_input_tokens and reads in cache_read_input_tokens.

Streaming

Append text_delta data from content_block_delta events by index. message_delta may carry stop reasons and usage. message_stop ends the stream. Retain the request ID if an error occurs or the connection closes early.

Example language
curl -NsS "https://api.saveapi.cc/v1/messages" \
  -H "x-api-key: $AI_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "claude-sonnet-5-5",
  "max_tokens": 256,
  "system": "You are a helpful assistant.",
  "messages": [
    {
      "role": "user",
      "content": "Hello"
    }
  ],
  "stream": true
}'

Error format

For a 400 response, check max_tokens and the message structure. For a 404, check how the SDK joins its base URL with /v1/messages and make sure /v1 is not repeated.

JSON
{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "max_tokens is required for Anthropic Messages requests. Add max_tokens or use /chat/completions for OpenAI-compatible requests."
  }
}