v49

latestOpenAPI 3.1.0raw.githubusercontent.com2026-07-261319281.7 MB

Create a Message

Send a structured list of input messages with text and/or image content, and the model will generate the next message in the conversation.

The Messages API can be used for either single queries or stateless multi-turn conversations.

Learn more about the Messages API in our user guide

post/v1/messages

Headers

anthropic-versionstring

The version of the Claude API you want to use.

Read more about versioning and our version history here.

The version of the Claude API you want to use.

Read more about versioning and our version history here.

anthropic-user-profile-idstring

The user profile ID to attribute this request to. Use when acting on behalf of a party other than your organization. Requires the user-profiles beta header.

The user profile ID to attribute this request to. Use when acting on behalf of a party other than your organization. Requires the user-profiles beta header.

Request body

containerstring nullable

Container identifier for reuse across requests.

inference_geostring nullable

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

max_tokensinteger 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.

service_tier'auto' | 'standard_only'

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.

stop_sequencesstring[]

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.

streamboolean

Whether to incrementally stream the response using server-sent events.

See streaming for details.

temperaturenumber

Amount of randomness injected into the response.

Defaults to 1.0. Ranges from 0.0 to 1.0. Use temperature closer to 0.0 for analytical / multiple choice, and closer to 1.0 for creative and generative tasks.

Note that even with temperature of 0.0, the results will not be fully deterministic.

top_kinteger

Only sample from the top K options for each subsequent token.

Used to remove "long tail" low probability responses. Learn more technical details here.

Recommended for advanced use cases only.

top_pnumber

Use nucleus sampling.

In nucleus sampling, we compute the cumulative distribution over all the options for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified by top_p.

Recommended for advanced use cases only.

Example request

{
  "max_tokens": 1024,
  "messages": [
    {
      "content": "Hello, world",
      "role": "user"
    }
  ],
  "model": "claude-opus-4-6"
}

Response

Message object.

idstring required

Unique object identifier.

The format and length of IDs may change over time.

type'message' required

Object type.

For Messages, this is always "message".

role'assistant' required

Conversational role of the generated message.

This will always be "assistant".

stop_reason'end_turn' | 'max_tokens' | 'stop_sequence' | 'tool_use' | 'pause_turn' | 'refusal' | 'model_context_window_exceeded' required
stop_sequencestring nullable 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.

Example response

{
  "content": [
    {
      "citations": null,
      "text": "Hi! My name is Claude.",
      "type": "text"
    }
  ],
  "id": "msg_013Zva2CMHLNnXjNJJKqJ2EF",
  "model": "claude-opus-4-6",
  "role": "assistant",
  "stop_details": null,
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "type": "message",
  "usage": {
    "input_tokens": 2095,
    "output_tokens": 503
  }
}
All 174 operations