Create a Message
Create a Message through the OMA API.
Authorizations
OMA workspace API key.
Headers
Optional header to specify the beta version(s) you want to use.
To use multiple betas, use a comma separated list like beta1,beta2 or specify the header multiple times for each beta.
The version of the OMA API you want to use.
Read more about versioning and our version history here.
The user profile ID to attribute this request to. Use when acting on behalf of a party other than your organization. Requires the user-profiles beta header.
Query Parameters
Selects the beta API contract for this endpoint. Must be true.
true Body
The model that will complete your prompt.
See models for additional details and options.
Input messages.
Our models are trained to operate on alternating user and assistant conversational turns. When creating a new Message, you specify the prior conversational turns with the messages parameter, and the model then generates the next Message in the conversation. Consecutive user or assistant turns in your request will be combined into a single turn.
Each input message must be an object with a role and content. You can specify a single user-role message, or you can include multiple user and assistant messages.
If the final message uses the assistant role, the response content will continue immediately from the content in that message. This can be used to constrain part of the model's response.
Example with a single user message:
Example with multiple conversational turns:
Example with a partially-filled response from the model:
Each input message content may be either a single string or an array of content blocks, where each block has a specific type. Using a string for content is shorthand for an array of one content block of type "text". The following input messages are equivalent:
See input examples.
Note that if you want to include a system prompt, you can use the top-level system parameter — there is no "system" role for input messages in the Messages API.
There is a limit of 100,000 messages in a single request.
The maximum number of tokens to generate before stopping.
Note that our models may stop before reaching this maximum. This parameter only specifies the absolute maximum number of tokens to generate.
Set to 0 to populate the prompt cache without generating a response.
Different models have different maximum values for this parameter. See models for details.
x >= 01024
Top-level cache control automatically applies a cache_control marker to the last cacheable block in the request.
Container parameters with skills to be loaded.
Context management configuration.
This allows you to control how the model manages context across multiple requests, such as whether to clear function results or not.
Request-level diagnostics. Supply previous_message_id to have the response include diagnostics.cache_miss_reason explaining any prompt-cache divergence from that prior request.
The fallback_credit_token from a prior refusal's stop_details.
When a preceding request was refused and returned a fallback_credit_token,
pass that code here on the retry to have the retry's cache-creation tokens
for the prefix that was warm on the refused model billed at the cache-read
rate. Must be redeemed by the same organization and workspace, with the same
request body (optionally extended by one appended assistant message whose
content is the partial text — with any trailing whitespace stripped from
the final text block — and paired server-tool blocks streamed before the
refusal; the appended-assistant form is not available for requests with
output_format set or forced tool_choice), on an eligible fallback
model, on the same platform,
and within 5 minutes of the refusal; a mismatch is a 400. A token minted
mid-server-tool-loop whose partial content was continuable may only be
redeemed with the appended-assistant form — if an exact-body retry is
rejected with a 400 saying the token must be redeemed by continuing the
partial response, retry with the appended-assistant form instead.
When the appended-assistant form is used on a model that otherwise disallows assistant-turn prefill, this token also authorizes that one prefill.
1 - 2048Opt-in server-side retry on one or more substitute models when the requested model declines for policy reasons. Tried in order: if the first entry also declines, the second is tried, and so on. The string "default" requests the requested model's server-defined default fallback configuration.
1 - 3 elementsSpecifies the geographic region for inference processing. If not specified, the workspace's default_inference_geo is used.
MCP servers to be utilized in this request
20An object describing metadata about the request.
Configuration options for the model's output, such as the output format.
Deprecated: Use output_config.format instead. See structured outputs
A schema to specify the model's output format in responses. This parameter will be removed in a future release.
Determines whether to use priority capacity (if available) or standard capacity for this request.
OMA offers different levels of service for your API requests. See service-tiers for details.
auto, standard_only The inference speed mode for this request. "fast" enables high output-tokens-per-second inference.
standard, fast 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.
Whether to incrementally stream the response using server-sent events.
See streaming for details.
false
System prompt.
A system prompt is a way of providing context and instructions to the model, such as specifying a particular goal or role. See our guide to system prompts.
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.
0 <= x <= 11
Configuration for enabling the model's extended thinking.
When enabled, responses include thinking content blocks showing the model's thinking process before the final answer. Requires a minimum budget of 1,024 tokens and counts towards your max_tokens limit.
See extended thinking for details.
- ThinkingConfigEnabled
- ThinkingConfigDisabled
- ThinkingConfigAdaptive
The model will automatically decide whether to use tools.
- ToolChoiceAuto
- ToolChoiceAny
- ToolChoiceTool
- ToolChoiceNone
Definitions of tools that the model may use.
If you include tools in your API request, the model may return tool_use content blocks that represent the model's use of those tools. You can then run those tools using the tool input generated by the model and then optionally return results back to the model using tool_result content blocks.
There are two types of tools: client tools and server tools. The behavior described below applies to client tools. For server tools, see their individual documentation as each has its own behavior (e.g., the web search tool).
Each tool definition includes:
name: Name of the tool.description: Optional, but strongly-recommended description of the tool.input_schema: JSON schema for the toolinputshape that the model will produce intool_useoutput content blocks.
For example, if you defined tools as:
And then asked the model "What's the S&P 500 at today?", the model might produce tool_use content blocks in the response like this:
You might then run your get_stock_price tool with {"ticker": "^GSPC"} as an input, and return the following back to the model in a subsequent user message:
Tools can be used for workflows that include running client-side tools and functions, or more generally whenever you want the model to produce a particular JSON structure of output.
See our guide for more details.
- Tool
- BashTool_20241022
- BashTool_20250124
- CodeExecutionTool_20250522
- CodeExecutionTool_20250825
- CodeExecutionTool_20260120
- CodeExecutionTool_20260521
- ComputerUseTool_20241022
- MemoryTool_20250818
- ComputerUseTool_20250124
- TextEditor_20241022
- ComputerUseTool_20251124
- TextEditor_20250124
- TextEditor_20250429
- TextEditor_20250728
- WebSearchTool_20250305
- WebFetchTool_20250910
- WebSearchTool_20260209
- WebFetchTool_20260209
- WebFetchTool_20260309
- WebSearchTool_20260318
- WebFetchTool_20260318
- AdvisorTool_20260301
- ToolSearchToolBM25_20251119
- ToolSearchToolRegex_20251119
- MCPToolset
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.
x >= 05
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.
Recommended for advanced use cases only.
0 <= x <= 10.7
Response
Message object.
Unique object identifier.
The format and length of IDs may change over time.
"msg_013Zva2CMHLNnXjNJJKqJ2EF"
Object type.
For Messages, this is always "message".
"message"Conversational role of the generated message.
This will always be "assistant".
"assistant"Content generated by the model.
This is an array of content blocks, each of which has a type that determines its shape.
Example:
If the request input messages ended with an assistant turn, then the response content will continue directly from that last turn. You can use this to constrain the model's output.
For example, if the input messages were:
Then the response content might be:
- ResponseTextBlock
- ResponseThinkingBlock
- ResponseRedactedThinkingBlock
- ResponseToolUseBlock
- ResponseServerToolUseBlock
- ResponseWebSearchToolResultBlock
- ResponseWebFetchToolResultBlock
- ResponseAdvisorToolResultBlock
- ResponseCodeExecutionToolResultBlock
- ResponseBashCodeExecutionToolResultBlock
- ResponseTextEditorCodeExecutionToolResultBlock
- ResponseToolSearchToolResultBlock
- ResponseMCPToolUseBlock
- ResponseMCPToolResultBlock
- ResponseContainerUploadBlock
- ResponseCompactionBlock
- ResponseFallbackBlock
The model that will complete your prompt.
See models for additional details and options.
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 requestedmax_tokensor the model's maximum"stop_sequence": one of your provided customstop_sequenceswas generated"tool_use": the model invoked one or more tools"pause_turn": we paused a long-running turn. You may provide the response back as-is in a subsequent request to let the model continue."refusal": when streaming classifiers intervene to handle potential policy violations"model_context_window_exceeded": we exceeded the model's context window
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.
end_turn, max_tokens, stop_sequence, tool_use, pause_turn, compaction, refusal, model_context_window_exceeded 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.
Structured information about why model output stopped.
This is null when the stop_reason has no additional detail to report.
Billing and rate-limit usage.
OMA's API bills and rate-limits by token counts, as tokens represent the underlying cost to our systems.
Under the hood, the API transforms requests into a format suitable for the model. The model's output then goes through a parsing stage before becoming an API response. As a result, the token counts in usage will not match one-to-one with the exact visible content of an API request or response.
For example, output_tokens will be non-zero, even for an empty string response from the model.
Total input tokens in a request is the summation of input_tokens, cache_creation_input_tokens, and cache_read_input_tokens.
Request-level diagnostics. Present only when diagnostics was supplied on the request; null when no prompt-cache divergence was detected.
Context management response.
Information about context management strategies applied during the request.
Information about the container used in this request.
This will be non-null if a container tool (e.g. code execution) was used.