The Messages API lets you send messages with text or images, and receive a response from the AI model. You can use it in two main ways:
Simple sync request:
Async (stream) request:
Response:
Supported options:
model (string)
- LLM model to process your request
messages (list)
- list of messages (see example above)
max_tokens (number)
- the maximum number of tokens to generate before stopping
metadata (hash)
- an object describing metadata about the request
stop_sequences (list)
- custom text sequences that will cause the model to stop generating
stream (boolean)
- whether to incrementally stream the response using server-sent events
system (string)
- system prompt
temperature (float)
- system prompt
tool_choice (hash)
- how the model should use the provided tools
tools (list)
- definitions of tools that the model may use
top_k (number)
- only sample from the top K options for each subsequent token
top_p (float)
- use nucleus sampling