# 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](../../../../guides/billing/credentials.md#choose-credential-type). [Find and select a model](models.md) that supports Messages, and prepare the messages to send.

## Call sequence

1. If you need to check input size before generation, [count input tokens](../../../../reference/api/genesis/text-generation/count-tokens.md) for the target model and messages. This step is optional.
2. [Create a Message](../../../../reference/api/genesis/text-generation/anthropic-messages.md) using the selected model and messages, and set the required output length limit.
3. 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 | [Count input tokens](../../../../reference/api/genesis/text-generation/count-tokens.md) | Optionally check before generation; this operation does not generate a reply. |
| Generate a message reply | [Create a Message](../../../../reference/api/genesis/text-generation/anthropic-messages.md) | 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.
