v1

latestOpenAPI 3.1.0Proprietary2026-07-2631521.2 KB
Messages

Create message

Create conversational messages using the Anthropic-compatible Messages API

post/messages

Headers

anthropic-versionstring required
Example:2023-06-01

The version of the Anthropic API you want to use. Use '2023-06-01' for the current stable version.

anthropic-betastring
Example:max-tokens-3-5-sonnet-2022-07-15

Optional header for accessing beta features. Format: comma-separated list of beta feature names.

Request body

modelstring required

The model that will complete your prompt. See the list of Claude models at https://docs.claude.com/en/docs/about-claude/models

max_tokensinteger required

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

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.

top_pnumber

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

top_kinteger

Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. Recommended for advanced use cases only. You usually only need to use temperature.

streamboolean

Whether to incrementally stream the response using server-sent events. See streaming documentation for details.

stop_sequencesstring[]

Custom text sequences that will cause the model to stop generating. Claude will stop when it encounters any of these strings.

service_tier'auto' | 'standard_only'

The service tier to use for the request. 'auto' lets us choose the tier, 'standard_only' restricts to standard tier.

Example request

{
  "model": "claude-3.5-sonnet"
}

Response

Successful response

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 is always 'assistant'.

modelstring required

The model that handled the request.

stop_reason'end_turn' | 'max_tokens' | 'stop_sequence' | 'tool_use' required

The reason that we stopped. This may be one of 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), or tool_use (the model invoked one or more tools).

stop_sequencestring nullable

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

{
  "id": "msg_abc123",
  "model": "claude-3.5-sonnet"
}