This guide walks you through installing theDocumentation 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.
aisdk/anthropic package, authenticating with your Anthropic API key, and running a basic text generation request against a Claude model. By the end you will have a working PHP script that calls the Anthropic API and prints the model’s response.
Install via Composer
Add
aisdk/anthropic to your project using Composer. The aisdk/core package is pulled in automatically as a dependency.Set your API key
Export your Anthropic API key as an environment variable. The provider reads You can also set the key in a
ANTHROPIC_API_KEY automatically — no extra bootstrap code needed..env file and load it with your framework’s environment helper, or pass it directly via Anthropic::create() (see Configuration).Generate your first response
Use
Generate::text() to build a request, attach a Claude model with Anthropic::model(), add an instruction and a prompt, then call ->run() to execute.$result->text contains the plain-text response from Claude. The ->instructions() call maps to Anthropic’s top-level system field.Set a default model
If every request in your application targets the same model, register it once with This is particularly useful in service providers or bootstrap files where you configure the SDK once at startup.
Generate::model(). Subsequent calls to Generate::text() will use it automatically without repeating ->model().Next Steps
Now that you have a working request, explore the rest of whataisdk/anthropic supports.
Streaming
Stream Claude’s response token-by-token for real-time output in your UI.
Tool Calling
Give Claude access to your PHP functions and let it call them automatically.
Structured Output
Receive validated JSON objects matching a schema you define.
Configuration
Customise the base URL, version header, and additional HTTP headers.