v1

latestOpenAPI 3.0.32026-07-175615.8 KB

Create a new message conversation with Claude

Sends a message or a series of messages to Claude and retrieves a response, optionally including thinking traces.

post/v1/messages

Request body

modelstring required

The Claude model to use (e.g., claude-3-5-sonnet-20241022).

max_tokensinteger required

Maximum number of tokens to generate in the response.

temperaturenumber

Controls randomness of the response (0 to 1). Lower for analytical, higher for creative tasks.

systemstring

Optional system prompt to set context or instructions for Claude.

top_pnumber

Nucleus sampling parameter (0 to 1).

top_kinteger

Only sample from the top K options for each token.

Example request

{
  "model": "claude-3-5-sonnet-20241022",
  "messages": [
    {
      "role": "user",
      "content": "Hello, how can I assist you today?"
    }
  ],
  "max_tokens": 1024,
  "temperature": 0.7,
  "system": "You are a helpful assistant created by Anthropic.",
  "top_p": 0.9,
  "top_k": 40
}

Response

Successful response with Claude's reply and optional thinking trace

idstring

Unique identifier for the message response.

typestring

Type of response, always "message" for this endpoint.

rolestring

Role of the responder, always "assistant".

Example response

{
  "id": "msg_12345",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "Hi there! I'm here to help you with any questions."
    }
  ]
}
All 5 operations