You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ PydanticAI is a Python Agent Framework designed to make it less painful to build
32
32
## Why use PydanticAI
33
33
34
34
* Built by the team behind Pydantic (the validation layer of the OpenAI SDK, the Anthropic SDK, LangChain, LlamaIndex, AutoGPT, Transformers, CrewAI, Instructor and many more)
35
-
* Model-agnostic — currently OpenAI, Gemini, and Groq are supported. And there is a simple interface to implement support for other models.
35
+
* Model-agnostic — currently OpenAI, Gemini, Anthropic, and Groq are supported. And there is a simple interface to implement support for other models.
* Control flow and agent composition is done with vanilla Python, allowing you to make use of the same Python development best practices you'd use in any other (non-AI) project
38
38
*[Structured response](https://ai.pydantic.dev/results/#structured-result-validation) validation with Pydantic
Copy file name to clipboardExpand all lines: docs/index.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ PydanticAI is a Python Agent Framework designed to make it less painful to build
11
11
## Why use PydanticAI
12
12
13
13
* Built by the team behind Pydantic (the validation layer of the OpenAI SDK, the Anthropic SDK, LangChain, LlamaIndex, AutoGPT, Transformers, CrewAI, Instructor and many more)
14
-
* Model-agnostic — currently OpenAI, Gemini, and Groq are supported, Anthropic [is coming soon](https://github.com/pydantic/pydantic-ai/issues/63). And there is a simple interface to implement support for other models.
14
+
* Model-agnostic — currently OpenAI, Gemini, Anthropic, and Groq are supported, Anthropic [is coming soon](https://github.com/pydantic/pydantic-ai/issues/63). And there is a simple interface to implement support for other models.
15
15
*[Type-safe](agents.md#static-type-checking)
16
16
* Control flow and agent composition is done with vanilla Python, allowing you to make use of the same Python development best practices you'd use in any other (non-AI) project
17
17
*[Structured response](results.md#structured-result-validation) validation with Pydantic
@@ -60,6 +61,12 @@ If you're using just [`VertexAIModel`][pydantic_ai.models.vertexai.VertexAIModel
60
61
pip/uv-add 'pydantic-ai-slim[vertexai]'
61
62
```
62
63
64
+
If you're just using [`Anthropic`][pydantic_ai.models.anthropic.AnthropicModel], run:
65
+
66
+
```bash
67
+
pip/uv-add 'pydantic-ai-slim[anthropic]'
68
+
```
69
+
63
70
To use just [`GroqModel`][pydantic_ai.models.groq.GroqModel], run:
64
71
65
72
```bash
@@ -277,6 +284,53 @@ agent = Agent(model)
277
284
278
285
[`VertexAiRegion`][pydantic_ai.models.vertexai.VertexAiRegion] contains a list of available regions.
279
286
287
+
### Anthropic
288
+
289
+
To use [Anthropic](https://docs.anthropic.com/en/home) through their API, go to [console.anthropic.com/settings/keys](https://console.anthropic.com/settings/keys) to generate an API key.
290
+
291
+
[`AnthropicModelName`][pydantic_ai.models.anthropic.AnthropicModelName] contains a list of available Anthropic models.
292
+
293
+
#### Environment variable
294
+
295
+
Once you have the API key, you can set it as an environment variable:
296
+
297
+
```bash
298
+
export ANTHROPIC_API_KEY='your-api-key'
299
+
```
300
+
301
+
You can then use [`AnthropicModel`][pydantic_ai.models.anthropic.AnthropicModel] by name:
302
+
303
+
```py title="anthropic_model_by_name.py"
304
+
from pydantic_ai import Agent
305
+
306
+
agent = Agent('claude-3-5-sonnet-latest')
307
+
...
308
+
```
309
+
310
+
Or initialise the model directly with just the model name:
311
+
312
+
```py title="anthropic_model_init.py"
313
+
from pydantic_ai import Agent
314
+
from pydantic_ai.models.anthropic import AnthropicModel
315
+
316
+
model = AnthropicModel('claude-3-5-sonnet-latest')
317
+
agent = Agent(model)
318
+
...
319
+
```
320
+
321
+
#### `api_key` argument
322
+
323
+
If you don't want to or can't set the environment variable, you can pass it at runtime via the [`api_key` argument][pydantic_ai.models.anthropic.AnthropicModel.__init__]:
324
+
325
+
```py title="anthropic_model_api_key.py"
326
+
from pydantic_ai import Agent
327
+
from pydantic_ai.models.anthropic import AnthropicModel
328
+
329
+
model = AnthropicModel('claude-3-5-sonnet-latest', api_key='your-api-key')
330
+
agent = Agent(model)
331
+
...
332
+
```
333
+
280
334
### Groq
281
335
282
336
To use [Groq](https://groq.com/) through their API, go to [console.groq.com/keys](https://console.groq.com/keys) and follow your nose until you find the place to generate an API key.
0 commit comments