Messages

Messages

post

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.

Header parameters
x-api-keystringRequired

Your unique API key for authentication.

Example: sk-lh7cVWdVZx7lFkVmf92yFaz3uwWwiwMXfOESPnbpLtPKB3Oi
Body
modelstringRequired

The model that will complete your prompt.

Example: claude-3-7-sonnet-20250219
max_tokensinteger · min: 1Required

The maximum number of tokens to generate before stopping.

Example: 1024
stop_sequencesstring[]Optional

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.

streambooleanOptional

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

temperaturenumber · max: 1Optional

Amount of randomness injected into the response.

Default: 1
top_knumberOptional

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

Example: 5
top_pnumber · max: 1Optional

Use nucleus sampling.

Example: 0.7
Responses
chevron-right
200Success
application/json
modelstringRequired
idstringRequired
typestringRequired
rolestringRequired
stop_reasonstringRequired
stop_sequencenullRequired
post
/v1/messages
200Success

Last updated