Messages

Create a Message

Changed on

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.

post/anthropic/{region}/v1/messages

Request

  • Base URL
    https://api.langdock.com
  • URL
    https://api.langdock.com/anthropic/{region}/v1/messages
  • Auth
    HTTP bearer

Path parameters

region'eu' | 'us' required

The region of the API to use.

Request body

modelstring required

The model that will complete your prompt. See models for additional details and options.

max_tokensinteger required

The maximum number of tokens to generate before stopping.

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

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

stop_sequencesstring[]

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

Anthropic's 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. You usually only need to use temperature.

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. You should either alter temperature or top_p, but not both.

Recommended for advanced use cases only. You usually only need to use temperature.

Example request

{
  "max_tokens": 1024,
  "messages": [
    {
      "content": "Write a haiku about cats.",
      "role": "user"
    }
  ],
  "model": "claude-sonnet-4-20250514"
}

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'agent' required

Conversational role of the generated message.

This will always be "assistant".

modelstring required

The model that will complete your prompt. See models for additional details and options.

stop_reason'end_turn' | 'max_tokens' | 'stop_sequence' | 'tool_use' 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

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.

stop_sequencestring 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": [
    [
      {
        "text": "Hi! My name is Claude.",
        "type": "text"
      }
    ]
  ]
}

Changes