Documentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/anthropic/llms.txt
Use this file to discover all available pages before exploring further.
Generate::text() sends a request to POST /messages on the Anthropic Messages API and returns a TextModelResponse containing the generated text, token usage, finish reason, and the raw API payload. The provider handles authentication, serialization, and response parsing automatically.
Basic Usage
Attach a model, optional instructions, and a prompt, then call->run() to receive the complete response.
System Instructions
There are two ways to supply system-level instructions and both are merged into the Anthropic top-levelsystem field before the request is sent.
Via .instructions() — a convenience string attached directly to the generation request:
Message::system() in multi-turn history — system entries placed inside the messages array are extracted and appended to the same system field:
system: "Be terse\n\nUse metric units". The Message::system() entry is removed from the messages array before it is sent — Anthropic does not accept system-role messages inside the messages field.
Response Fields
| Field | Type | Description |
|---|---|---|
$result->text | string | The generated text content. |
$result->usage->inputTokens | int | Number of tokens in the prompt and system instructions. |
$result->usage->outputTokens | int | Number of tokens in the generated response. |
$result->finishReason | FinishReason | One of Stop, Length, ToolCalls, or Unknown. |
$result->rawResponse | array | The full, unmodified response payload returned by the Anthropic API. |
finishReason values map from Anthropic stop reasons as follows:
Anthropic stop_reason | SDK FinishReason |
|---|---|
end_turn, stop_sequence | Stop |
max_tokens | Length |
tool_use | ToolCalls |
| (any other value) | Unknown |
Setting a Default Model
To avoid specifying a model on every call, register a default model once at application bootstrap usingGenerate::model(). All subsequent Generate::text() calls will use it automatically.