Skip to main content
POST

Authorizations

x-api-key
string
header
required

Send your DreamTo API Key in the x-api-key header, the way the Anthropic SDKs do by default.

Headers

anthropic-version
string

The version of the Claude API you want to use.

Read more about versioning and our version history here.

Body

application/json
max_tokens
number
required

The maximum number of tokens to generate before stopping.

Note that our models may stop before reaching this maximum. This parameter only specifies the absolute maximum number of tokens to generate.

Set to 0 to populate the prompt cache without generating a response.

Different models have different maximum values for this parameter. See models for details.

Required range: x >= 0
messages
object[]
required

Input messages.

Our models are trained to operate on alternating user and assistant conversational turns. When creating a new Message, you specify the prior conversational turns with the messages parameter, and the model then generates the next Message in the conversation. Consecutive user or assistant turns in your request will be combined into a single turn.

Each input message must be an object with a role and content. You can specify a single user-role message, or you can include multiple user and assistant messages.

If the final message uses the assistant role, the response content will continue immediately from the content in that message. This can be used to constrain part of the model's response. This is called prefill. On models that don't support prefill, creating a message that ends with a partial assistant response returns a 400 error. See Prefill not supported.

Example with a single user message:

Example with multiple conversational turns:

Example with a partially-filled response from Claude, for models that support prefill:

Each input message content may be either a single string or an array of content blocks, where each block has a specific type. Using a string for content is shorthand for an array of one content block of type "text". The following input messages are equivalent:

See input examples.

Note that if you want to include a system prompt, you can use the top-level system parameter.

There is a limit of 100,000 messages in a single request.

model
string
required

ID of the model to use, for example claude-sonnet-5-5. See Models for the available models.

Example:

"claude-sonnet-5-5"

cache_control
object | null

Top-level cache control automatically applies a cache_control marker to the last cacheable block in the request.

container

Container identifier for reuse across requests.

diagnostics
object | null

Request-level diagnostics. Supply previous_message_id to have the response include diagnostics.cache_miss_reason explaining any prompt-cache divergence from that prior request.

inference_geo
string | null

Specifies the geographic region for inference processing. If not specified, the workspace's default_inference_geo is used.

metadata
object

An object describing metadata about the request.

output_config
object

Configuration options for the model's output, such as the output format.

service_tier
enum<string>

Determines whether to use priority capacity (if available) or standard capacity for this request.

Anthropic offers different levels of service for your API requests. See service-tiers for details.

Available options:
auto,
standard_only
speed
enum<string> | null

The inference speed mode for this request. "fast" enables high output-tokens-per-second inference.

Some models require the fast-mode-2026-02-01 beta header for any speed value. See fast mode for which models.

Available options:
standard,
fast
stop_sequences
string[]

Custom text sequences that will cause the model to stop generating.

Our models will normally stop when they have naturally completed their turn, which will result in a response stop_reason of "end_turn".

If you want the model to stop generating when it encounters custom strings of text, you can use the stop_sequences parameter. If the model encounters one of the custom sequences, the response stop_reason value will be "stop_sequence" and the response stop_sequence value will contain the matched stop sequence.

stream
boolean

Whether to incrementally stream the response using server-sent events. When true, SDKs return a raw event stream.

In the TypeScript, Python and Ruby SDKs, the recommended way to stream is messages.stream(). It sets stream for you and accumulates the events into the final message. See Streaming with SDKs for an example in each language.

system

System prompt.

A system prompt is a way of providing context and instructions to Claude, such as specifying a particular goal or role. See our guide to system prompts.

thinking
object

Configuration for Claude's thinking.

With {"type": "adaptive"}, Claude decides when and how much to think. With {"type": "enabled"} (manual extended thinking), you set a budget_tokens of at least 1,024. Thinking tokens count toward your max_tokens limit.

Which type values are accepted, and what happens when you omit thinking, depend on the model. See thinking for each model's behavior.

tool_choice
object

How the model should use the provided tools. The model can use a specific tool, any available tool, decide by itself, or not use tools at all.

tools
object[]

Definitions of tools that the model may use.

If you include tools in your API request, the model may return tool_use content blocks that represent the model's use of those tools. You can then run those tools using the tool input generated by the model and then optionally return results back to the model using tool_result content blocks.

There are two types of tools: client tools and server tools. The behavior described below applies to client tools. For server tools, see their individual documentation as each has its own behavior (e.g., the web search tool).

Each tool definition includes:

  • name: Name of the tool.
  • description: Optional, but strongly-recommended description of the tool.
  • input_schema: JSON schema for the tool input shape that the model will produce in tool_use output content blocks.

For example, if you defined tools as:

And then asked the model "What's the S&P 500 at today?", the model might produce tool_use content blocks in the response like this:

You might then run your get_stock_price tool with {"ticker": "^GSPC"} as an input, and return the following back to the model in a subsequent user message:

Tools can be used for workflows that include running client-side tools and functions, or more generally whenever you want the model to produce a particular JSON structure of output.

See our guide for more details.

Response

A Message object for a non-streaming request; with stream: true, server-sent events (text/event-stream), each a RawMessageStreamEvent.

type
string
required

Object type.

For Messages, this is always "message".

Allowed value: "message"
id
string
required

Unique object identifier.

The format and length of IDs may change over time.

container
object | null
required

Information about the container used in this request.

This will be non-null if a container tool (e.g. code execution) was used.

content
object[]
required

Content generated by the model.

This is an array of content blocks, each of which has a type that determines its shape.

Example:

If the request input messages ended with an assistant turn, then the response content will continue directly from that last turn. You can use this to constrain the model's output.

For example, if the input messages were:

Then the response content might be:

diagnostics
object | null
required

Request-level diagnostics. null when the request did not supply diagnostics, or when it did and no prompt-cache divergence was detected.

model
required

The model that will complete your prompt.

See models for additional details and options.

Allowed value: "claude-fable-5-2"
role
string
required

Conversational role of the generated message.

This will always be "assistant".

Allowed value: "assistant"
stop_details
object | null
required

Structured information about why model output stopped.

This is null when the stop_reason has no additional detail to report.

stop_reason
enum<string> | null
required

The reason that we stopped.

This may be one the following values:

  • "end_turn": the model reached a natural stopping point
  • "max_tokens": we exceeded the requested max_tokens or the model's maximum
  • "stop_sequence": one of your provided custom stop_sequences was generated
  • "tool_use": the model invoked one or more tools
  • "pause_turn": we paused a long-running turn. You may provide the response back as-is in a subsequent request to let the model continue.
  • "refusal": when streaming classifiers intervene to handle potential policy violations
  • "model_context_window_exceeded": we exceeded the model's context window

In non-streaming mode this value is always non-null. In streaming mode, it is null in the message_start event and non-null otherwise.

Available options:
end_turn,
max_tokens,
stop_sequence,
tool_use,
pause_turn,
refusal,
model_context_window_exceeded
stop_sequence
string | null
required

Which custom stop sequence was generated, if any.

This value will be a non-null string if one of your custom stop sequences was generated.

usage
object
required

Billing and rate-limit usage.

Anthropic's API bills and rate-limits by token counts, as tokens represent the underlying cost to our systems.

Under the hood, the API transforms requests into a format suitable for the model. The model's output then goes through a parsing stage before becoming an API response. As a result, the token counts in usage will not match one-to-one with the exact visible content of an API request or response.

For example, output_tokens will be non-zero, even for an empty string response from Claude.

Total input tokens in a request is the summation of input_tokens, cache_creation_input_tokens, and cache_read_input_tokens.