Generate replies with Messages¶
Send messages through the Messages API and read the model reply. Optionally count input tokens before generation.
Prerequisites¶
Prepare a personal access token or service account API Key with Genesis permissions. See Access credentials. Find and select a model that supports Messages, and prepare the messages to send.
Call sequence¶
If you need to check input size before generation, count input tokens for the target model and messages. This step is optional.
Create a Message using the selected model and messages, and set the required output length limit.
Read the returned content blocks, stop reason, and usage. For streaming, process content blocks and the message completion event as described on the action page.
API operations¶
Task |
API operation |
When to use it or what to check |
|---|---|---|
Check input size |
Optionally check before generation; this operation does not generate a reply. |
|
Generate a message reply |
Send messages and receive complete content or streamed content blocks. |
Confirm the result¶
Token counting returns the number of input tokens. Check the content blocks and stop reason from the separate generation call. For streaming, confirm that the message completion event arrives.
Limitations and notes¶
Input token counting excludes the reply that has not yet been generated. Messages and Chat Completions use different streaming event structures; follow the respective action page.