pydantic-ai-slim 0.0.45__py3-none-any.whl → 0.0.47__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pydantic-ai-slim might be problematic. Click here for more details.

pydantic_ai/messages.py CHANGED
@@ -9,7 +9,7 @@ from typing import Annotated, Any, Literal, Union, cast, overload
9
9
 
10
10
  import pydantic
11
11
  import pydantic_core
12
- from opentelemetry._events import Event
12
+ from opentelemetry._events import Event # pyright: ignore[reportPrivateImportUsage]
13
13
  from typing_extensions import TypeAlias
14
14
 
15
15
  from ._utils import generate_tool_call_id as _generate_tool_call_id, now_utc as _now_utc
@@ -12,10 +12,10 @@ from contextlib import asynccontextmanager, contextmanager
12
12
  from dataclasses import dataclass, field
13
13
  from datetime import datetime
14
14
  from functools import cache
15
- from typing import TYPE_CHECKING, cast
15
+ from typing import TYPE_CHECKING
16
16
 
17
17
  import httpx
18
- from typing_extensions import Literal
18
+ from typing_extensions import Literal, TypeAliasType
19
19
 
20
20
  from .._parts_manager import ModelResponsePartsManager
21
21
  from ..exceptions import UserError
@@ -27,195 +27,209 @@ if TYPE_CHECKING:
27
27
  from ..tools import ToolDefinition
28
28
 
29
29
 
30
- KnownModelName = Literal[
31
- 'anthropic:claude-3-7-sonnet-latest',
32
- 'anthropic:claude-3-5-haiku-latest',
33
- 'anthropic:claude-3-5-sonnet-latest',
34
- 'anthropic:claude-3-opus-latest',
35
- 'claude-3-7-sonnet-latest',
36
- 'claude-3-5-haiku-latest',
37
- 'bedrock:amazon.titan-tg1-large',
38
- 'bedrock:amazon.titan-text-lite-v1',
39
- 'bedrock:amazon.titan-text-express-v1',
40
- 'bedrock:us.amazon.nova-pro-v1:0',
41
- 'bedrock:us.amazon.nova-lite-v1:0',
42
- 'bedrock:us.amazon.nova-micro-v1:0',
43
- 'bedrock:anthropic.claude-3-5-sonnet-20241022-v2:0',
44
- 'bedrock:us.anthropic.claude-3-5-sonnet-20241022-v2:0',
45
- 'bedrock:anthropic.claude-3-5-haiku-20241022-v1:0',
46
- 'bedrock:us.anthropic.claude-3-5-haiku-20241022-v1:0',
47
- 'bedrock:anthropic.claude-instant-v1',
48
- 'bedrock:anthropic.claude-v2:1',
49
- 'bedrock:anthropic.claude-v2',
50
- 'bedrock:anthropic.claude-3-sonnet-20240229-v1:0',
51
- 'bedrock:us.anthropic.claude-3-sonnet-20240229-v1:0',
52
- 'bedrock:anthropic.claude-3-haiku-20240307-v1:0',
53
- 'bedrock:us.anthropic.claude-3-haiku-20240307-v1:0',
54
- 'bedrock:anthropic.claude-3-opus-20240229-v1:0',
55
- 'bedrock:us.anthropic.claude-3-opus-20240229-v1:0',
56
- 'bedrock:anthropic.claude-3-5-sonnet-20240620-v1:0',
57
- 'bedrock:us.anthropic.claude-3-5-sonnet-20240620-v1:0',
58
- 'bedrock:anthropic.claude-3-7-sonnet-20250219-v1:0',
59
- 'bedrock:us.anthropic.claude-3-7-sonnet-20250219-v1:0',
60
- 'bedrock:cohere.command-text-v14',
61
- 'bedrock:cohere.command-r-v1:0',
62
- 'bedrock:cohere.command-r-plus-v1:0',
63
- 'bedrock:cohere.command-light-text-v14',
64
- 'bedrock:meta.llama3-8b-instruct-v1:0',
65
- 'bedrock:meta.llama3-70b-instruct-v1:0',
66
- 'bedrock:meta.llama3-1-8b-instruct-v1:0',
67
- 'bedrock:us.meta.llama3-1-8b-instruct-v1:0',
68
- 'bedrock:meta.llama3-1-70b-instruct-v1:0',
69
- 'bedrock:us.meta.llama3-1-70b-instruct-v1:0',
70
- 'bedrock:meta.llama3-1-405b-instruct-v1:0',
71
- 'bedrock:us.meta.llama3-2-11b-instruct-v1:0',
72
- 'bedrock:us.meta.llama3-2-90b-instruct-v1:0',
73
- 'bedrock:us.meta.llama3-2-1b-instruct-v1:0',
74
- 'bedrock:us.meta.llama3-2-3b-instruct-v1:0',
75
- 'bedrock:us.meta.llama3-3-70b-instruct-v1:0',
76
- 'bedrock:mistral.mistral-7b-instruct-v0:2',
77
- 'bedrock:mistral.mixtral-8x7b-instruct-v0:1',
78
- 'bedrock:mistral.mistral-large-2402-v1:0',
79
- 'bedrock:mistral.mistral-large-2407-v1:0',
80
- 'claude-3-5-sonnet-latest',
81
- 'claude-3-opus-latest',
82
- 'cohere:c4ai-aya-expanse-32b',
83
- 'cohere:c4ai-aya-expanse-8b',
84
- 'cohere:command',
85
- 'cohere:command-light',
86
- 'cohere:command-light-nightly',
87
- 'cohere:command-nightly',
88
- 'cohere:command-r',
89
- 'cohere:command-r-03-2024',
90
- 'cohere:command-r-08-2024',
91
- 'cohere:command-r-plus',
92
- 'cohere:command-r-plus-04-2024',
93
- 'cohere:command-r-plus-08-2024',
94
- 'cohere:command-r7b-12-2024',
95
- 'deepseek:deepseek-chat',
96
- 'deepseek:deepseek-reasoner',
97
- 'google-gla:gemini-1.0-pro',
98
- 'google-gla:gemini-1.5-flash',
99
- 'google-gla:gemini-1.5-flash-8b',
100
- 'google-gla:gemini-1.5-pro',
101
- 'google-gla:gemini-2.0-flash-exp',
102
- 'google-gla:gemini-2.0-flash-thinking-exp-01-21',
103
- 'google-gla:gemini-exp-1206',
104
- 'google-gla:gemini-2.0-flash',
105
- 'google-gla:gemini-2.0-flash-lite-preview-02-05',
106
- 'google-gla:gemini-2.0-pro-exp-02-05',
107
- 'google-vertex:gemini-1.0-pro',
108
- 'google-vertex:gemini-1.5-flash',
109
- 'google-vertex:gemini-1.5-flash-8b',
110
- 'google-vertex:gemini-1.5-pro',
111
- 'google-vertex:gemini-2.0-flash-exp',
112
- 'google-vertex:gemini-2.0-flash-thinking-exp-01-21',
113
- 'google-vertex:gemini-exp-1206',
114
- 'google-vertex:gemini-2.0-flash',
115
- 'google-vertex:gemini-2.0-flash-lite-preview-02-05',
116
- 'google-vertex:gemini-2.0-pro-exp-02-05',
117
- 'gpt-3.5-turbo',
118
- 'gpt-3.5-turbo-0125',
119
- 'gpt-3.5-turbo-0301',
120
- 'gpt-3.5-turbo-0613',
121
- 'gpt-3.5-turbo-1106',
122
- 'gpt-3.5-turbo-16k',
123
- 'gpt-3.5-turbo-16k-0613',
124
- 'gpt-4',
125
- 'gpt-4-0125-preview',
126
- 'gpt-4-0314',
127
- 'gpt-4-0613',
128
- 'gpt-4-1106-preview',
129
- 'gpt-4-32k',
130
- 'gpt-4-32k-0314',
131
- 'gpt-4-32k-0613',
132
- 'gpt-4-turbo',
133
- 'gpt-4-turbo-2024-04-09',
134
- 'gpt-4-turbo-preview',
135
- 'gpt-4-vision-preview',
136
- 'gpt-4o',
137
- 'gpt-4o-2024-05-13',
138
- 'gpt-4o-2024-08-06',
139
- 'gpt-4o-2024-11-20',
140
- 'gpt-4o-audio-preview',
141
- 'gpt-4o-audio-preview-2024-10-01',
142
- 'gpt-4o-audio-preview-2024-12-17',
143
- 'gpt-4o-mini',
144
- 'gpt-4o-mini-2024-07-18',
145
- 'gpt-4o-mini-audio-preview',
146
- 'gpt-4o-mini-audio-preview-2024-12-17',
147
- 'gpt-4o-mini-search-preview',
148
- 'gpt-4o-mini-search-preview-2025-03-11',
149
- 'gpt-4o-search-preview',
150
- 'gpt-4o-search-preview-2025-03-11',
151
- 'groq:gemma2-9b-it',
152
- 'groq:llama-3.1-8b-instant',
153
- 'groq:llama-3.2-11b-vision-preview',
154
- 'groq:llama-3.2-1b-preview',
155
- 'groq:llama-3.2-3b-preview',
156
- 'groq:llama-3.2-90b-vision-preview',
157
- 'groq:llama-3.3-70b-specdec',
158
- 'groq:llama-3.3-70b-versatile',
159
- 'groq:llama3-70b-8192',
160
- 'groq:llama3-8b-8192',
161
- 'groq:mixtral-8x7b-32768',
162
- 'mistral:codestral-latest',
163
- 'mistral:mistral-large-latest',
164
- 'mistral:mistral-moderation-latest',
165
- 'mistral:mistral-small-latest',
166
- 'o1',
167
- 'o1-2024-12-17',
168
- 'o1-mini',
169
- 'o1-mini-2024-09-12',
170
- 'o1-preview',
171
- 'o1-preview-2024-09-12',
172
- 'o3-mini',
173
- 'o3-mini-2025-01-31',
174
- 'openai:chatgpt-4o-latest',
175
- 'openai:gpt-3.5-turbo',
176
- 'openai:gpt-3.5-turbo-0125',
177
- 'openai:gpt-3.5-turbo-0301',
178
- 'openai:gpt-3.5-turbo-0613',
179
- 'openai:gpt-3.5-turbo-1106',
180
- 'openai:gpt-3.5-turbo-16k',
181
- 'openai:gpt-3.5-turbo-16k-0613',
182
- 'openai:gpt-4',
183
- 'openai:gpt-4-0125-preview',
184
- 'openai:gpt-4-0314',
185
- 'openai:gpt-4-0613',
186
- 'openai:gpt-4-1106-preview',
187
- 'openai:gpt-4-32k',
188
- 'openai:gpt-4-32k-0314',
189
- 'openai:gpt-4-32k-0613',
190
- 'openai:gpt-4-turbo',
191
- 'openai:gpt-4-turbo-2024-04-09',
192
- 'openai:gpt-4-turbo-preview',
193
- 'openai:gpt-4-vision-preview',
194
- 'openai:gpt-4o',
195
- 'openai:gpt-4o-2024-05-13',
196
- 'openai:gpt-4o-2024-08-06',
197
- 'openai:gpt-4o-2024-11-20',
198
- 'openai:gpt-4o-audio-preview',
199
- 'openai:gpt-4o-audio-preview-2024-10-01',
200
- 'openai:gpt-4o-audio-preview-2024-12-17',
201
- 'openai:gpt-4o-mini',
202
- 'openai:gpt-4o-mini-2024-07-18',
203
- 'openai:gpt-4o-mini-audio-preview',
204
- 'openai:gpt-4o-mini-audio-preview-2024-12-17',
205
- 'openai:gpt-4o-mini-search-preview',
206
- 'openai:gpt-4o-mini-search-preview-2025-03-11',
207
- 'openai:gpt-4o-search-preview',
208
- 'openai:gpt-4o-search-preview-2025-03-11',
209
- 'openai:o1',
210
- 'openai:o1-2024-12-17',
211
- 'openai:o1-mini',
212
- 'openai:o1-mini-2024-09-12',
213
- 'openai:o1-preview',
214
- 'openai:o1-preview-2024-09-12',
215
- 'openai:o3-mini',
216
- 'openai:o3-mini-2025-01-31',
217
- 'test',
218
- ]
30
+ KnownModelName = TypeAliasType(
31
+ 'KnownModelName',
32
+ Literal[
33
+ 'anthropic:claude-3-7-sonnet-latest',
34
+ 'anthropic:claude-3-5-haiku-latest',
35
+ 'anthropic:claude-3-5-sonnet-latest',
36
+ 'anthropic:claude-3-opus-latest',
37
+ 'claude-3-7-sonnet-latest',
38
+ 'claude-3-5-haiku-latest',
39
+ 'bedrock:amazon.titan-tg1-large',
40
+ 'bedrock:amazon.titan-text-lite-v1',
41
+ 'bedrock:amazon.titan-text-express-v1',
42
+ 'bedrock:us.amazon.nova-pro-v1:0',
43
+ 'bedrock:us.amazon.nova-lite-v1:0',
44
+ 'bedrock:us.amazon.nova-micro-v1:0',
45
+ 'bedrock:anthropic.claude-3-5-sonnet-20241022-v2:0',
46
+ 'bedrock:us.anthropic.claude-3-5-sonnet-20241022-v2:0',
47
+ 'bedrock:anthropic.claude-3-5-haiku-20241022-v1:0',
48
+ 'bedrock:us.anthropic.claude-3-5-haiku-20241022-v1:0',
49
+ 'bedrock:anthropic.claude-instant-v1',
50
+ 'bedrock:anthropic.claude-v2:1',
51
+ 'bedrock:anthropic.claude-v2',
52
+ 'bedrock:anthropic.claude-3-sonnet-20240229-v1:0',
53
+ 'bedrock:us.anthropic.claude-3-sonnet-20240229-v1:0',
54
+ 'bedrock:anthropic.claude-3-haiku-20240307-v1:0',
55
+ 'bedrock:us.anthropic.claude-3-haiku-20240307-v1:0',
56
+ 'bedrock:anthropic.claude-3-opus-20240229-v1:0',
57
+ 'bedrock:us.anthropic.claude-3-opus-20240229-v1:0',
58
+ 'bedrock:anthropic.claude-3-5-sonnet-20240620-v1:0',
59
+ 'bedrock:us.anthropic.claude-3-5-sonnet-20240620-v1:0',
60
+ 'bedrock:anthropic.claude-3-7-sonnet-20250219-v1:0',
61
+ 'bedrock:us.anthropic.claude-3-7-sonnet-20250219-v1:0',
62
+ 'bedrock:cohere.command-text-v14',
63
+ 'bedrock:cohere.command-r-v1:0',
64
+ 'bedrock:cohere.command-r-plus-v1:0',
65
+ 'bedrock:cohere.command-light-text-v14',
66
+ 'bedrock:meta.llama3-8b-instruct-v1:0',
67
+ 'bedrock:meta.llama3-70b-instruct-v1:0',
68
+ 'bedrock:meta.llama3-1-8b-instruct-v1:0',
69
+ 'bedrock:us.meta.llama3-1-8b-instruct-v1:0',
70
+ 'bedrock:meta.llama3-1-70b-instruct-v1:0',
71
+ 'bedrock:us.meta.llama3-1-70b-instruct-v1:0',
72
+ 'bedrock:meta.llama3-1-405b-instruct-v1:0',
73
+ 'bedrock:us.meta.llama3-2-11b-instruct-v1:0',
74
+ 'bedrock:us.meta.llama3-2-90b-instruct-v1:0',
75
+ 'bedrock:us.meta.llama3-2-1b-instruct-v1:0',
76
+ 'bedrock:us.meta.llama3-2-3b-instruct-v1:0',
77
+ 'bedrock:us.meta.llama3-3-70b-instruct-v1:0',
78
+ 'bedrock:mistral.mistral-7b-instruct-v0:2',
79
+ 'bedrock:mistral.mixtral-8x7b-instruct-v0:1',
80
+ 'bedrock:mistral.mistral-large-2402-v1:0',
81
+ 'bedrock:mistral.mistral-large-2407-v1:0',
82
+ 'claude-3-5-sonnet-latest',
83
+ 'claude-3-opus-latest',
84
+ 'cohere:c4ai-aya-expanse-32b',
85
+ 'cohere:c4ai-aya-expanse-8b',
86
+ 'cohere:command',
87
+ 'cohere:command-light',
88
+ 'cohere:command-light-nightly',
89
+ 'cohere:command-nightly',
90
+ 'cohere:command-r',
91
+ 'cohere:command-r-03-2024',
92
+ 'cohere:command-r-08-2024',
93
+ 'cohere:command-r-plus',
94
+ 'cohere:command-r-plus-04-2024',
95
+ 'cohere:command-r-plus-08-2024',
96
+ 'cohere:command-r7b-12-2024',
97
+ 'deepseek:deepseek-chat',
98
+ 'deepseek:deepseek-reasoner',
99
+ 'google-gla:gemini-1.0-pro',
100
+ 'google-gla:gemini-1.5-flash',
101
+ 'google-gla:gemini-1.5-flash-8b',
102
+ 'google-gla:gemini-1.5-pro',
103
+ 'google-gla:gemini-2.0-flash-exp',
104
+ 'google-gla:gemini-2.0-flash-thinking-exp-01-21',
105
+ 'google-gla:gemini-exp-1206',
106
+ 'google-gla:gemini-2.0-flash',
107
+ 'google-gla:gemini-2.0-flash-lite-preview-02-05',
108
+ 'google-gla:gemini-2.0-pro-exp-02-05',
109
+ 'google-vertex:gemini-1.0-pro',
110
+ 'google-vertex:gemini-1.5-flash',
111
+ 'google-vertex:gemini-1.5-flash-8b',
112
+ 'google-vertex:gemini-1.5-pro',
113
+ 'google-vertex:gemini-2.0-flash-exp',
114
+ 'google-vertex:gemini-2.0-flash-thinking-exp-01-21',
115
+ 'google-vertex:gemini-exp-1206',
116
+ 'google-vertex:gemini-2.0-flash',
117
+ 'google-vertex:gemini-2.0-flash-lite-preview-02-05',
118
+ 'google-vertex:gemini-2.0-pro-exp-02-05',
119
+ 'gpt-3.5-turbo',
120
+ 'gpt-3.5-turbo-0125',
121
+ 'gpt-3.5-turbo-0301',
122
+ 'gpt-3.5-turbo-0613',
123
+ 'gpt-3.5-turbo-1106',
124
+ 'gpt-3.5-turbo-16k',
125
+ 'gpt-3.5-turbo-16k-0613',
126
+ 'gpt-4',
127
+ 'gpt-4-0125-preview',
128
+ 'gpt-4-0314',
129
+ 'gpt-4-0613',
130
+ 'gpt-4-1106-preview',
131
+ 'gpt-4-32k',
132
+ 'gpt-4-32k-0314',
133
+ 'gpt-4-32k-0613',
134
+ 'gpt-4-turbo',
135
+ 'gpt-4-turbo-2024-04-09',
136
+ 'gpt-4-turbo-preview',
137
+ 'gpt-4-vision-preview',
138
+ 'gpt-4o',
139
+ 'gpt-4o-2024-05-13',
140
+ 'gpt-4o-2024-08-06',
141
+ 'gpt-4o-2024-11-20',
142
+ 'gpt-4o-audio-preview',
143
+ 'gpt-4o-audio-preview-2024-10-01',
144
+ 'gpt-4o-audio-preview-2024-12-17',
145
+ 'gpt-4o-mini',
146
+ 'gpt-4o-mini-2024-07-18',
147
+ 'gpt-4o-mini-audio-preview',
148
+ 'gpt-4o-mini-audio-preview-2024-12-17',
149
+ 'gpt-4o-mini-search-preview',
150
+ 'gpt-4o-mini-search-preview-2025-03-11',
151
+ 'gpt-4o-search-preview',
152
+ 'gpt-4o-search-preview-2025-03-11',
153
+ 'groq:distil-whisper-large-v3-en',
154
+ 'groq:gemma2-9b-it',
155
+ 'groq:llama-3.3-70b-versatile',
156
+ 'groq:llama-3.1-8b-instant',
157
+ 'groq:llama-guard-3-8b',
158
+ 'groq:llama3-70b-8192',
159
+ 'groq:llama3-8b-8192',
160
+ 'groq:whisper-large-v3',
161
+ 'groq:whisper-large-v3-turbo',
162
+ 'groq:playai-tts',
163
+ 'groq:playai-tts-arabic',
164
+ 'groq:qwen-qwq-32b',
165
+ 'groq:mistral-saba-24b',
166
+ 'groq:qwen-2.5-coder-32b',
167
+ 'groq:qwen-2.5-32b',
168
+ 'groq:deepseek-r1-distill-qwen-32b',
169
+ 'groq:deepseek-r1-distill-llama-70b',
170
+ 'groq:llama-3.3-70b-specdec',
171
+ 'groq:llama-3.2-1b-preview',
172
+ 'groq:llama-3.2-3b-preview',
173
+ 'groq:llama-3.2-11b-vision-preview',
174
+ 'groq:llama-3.2-90b-vision-preview',
175
+ 'mistral:codestral-latest',
176
+ 'mistral:mistral-large-latest',
177
+ 'mistral:mistral-moderation-latest',
178
+ 'mistral:mistral-small-latest',
179
+ 'o1',
180
+ 'o1-2024-12-17',
181
+ 'o1-mini',
182
+ 'o1-mini-2024-09-12',
183
+ 'o1-preview',
184
+ 'o1-preview-2024-09-12',
185
+ 'o3-mini',
186
+ 'o3-mini-2025-01-31',
187
+ 'openai:chatgpt-4o-latest',
188
+ 'openai:gpt-3.5-turbo',
189
+ 'openai:gpt-3.5-turbo-0125',
190
+ 'openai:gpt-3.5-turbo-0301',
191
+ 'openai:gpt-3.5-turbo-0613',
192
+ 'openai:gpt-3.5-turbo-1106',
193
+ 'openai:gpt-3.5-turbo-16k',
194
+ 'openai:gpt-3.5-turbo-16k-0613',
195
+ 'openai:gpt-4',
196
+ 'openai:gpt-4-0125-preview',
197
+ 'openai:gpt-4-0314',
198
+ 'openai:gpt-4-0613',
199
+ 'openai:gpt-4-1106-preview',
200
+ 'openai:gpt-4-32k',
201
+ 'openai:gpt-4-32k-0314',
202
+ 'openai:gpt-4-32k-0613',
203
+ 'openai:gpt-4-turbo',
204
+ 'openai:gpt-4-turbo-2024-04-09',
205
+ 'openai:gpt-4-turbo-preview',
206
+ 'openai:gpt-4-vision-preview',
207
+ 'openai:gpt-4o',
208
+ 'openai:gpt-4o-2024-05-13',
209
+ 'openai:gpt-4o-2024-08-06',
210
+ 'openai:gpt-4o-2024-11-20',
211
+ 'openai:gpt-4o-audio-preview',
212
+ 'openai:gpt-4o-audio-preview-2024-10-01',
213
+ 'openai:gpt-4o-audio-preview-2024-12-17',
214
+ 'openai:gpt-4o-mini',
215
+ 'openai:gpt-4o-mini-2024-07-18',
216
+ 'openai:gpt-4o-mini-audio-preview',
217
+ 'openai:gpt-4o-mini-audio-preview-2024-12-17',
218
+ 'openai:gpt-4o-mini-search-preview',
219
+ 'openai:gpt-4o-mini-search-preview-2025-03-11',
220
+ 'openai:gpt-4o-search-preview',
221
+ 'openai:gpt-4o-search-preview-2025-03-11',
222
+ 'openai:o1',
223
+ 'openai:o1-2024-12-17',
224
+ 'openai:o1-mini',
225
+ 'openai:o1-mini-2024-09-12',
226
+ 'openai:o1-preview',
227
+ 'openai:o1-preview-2024-09-12',
228
+ 'openai:o3-mini',
229
+ 'openai:o3-mini-2025-01-31',
230
+ 'test',
231
+ ],
232
+ )
219
233
  """Known model names that can be used with the `model` parameter of [`Agent`][pydantic_ai.Agent].
220
234
 
221
235
  `KnownModelName` is provided as a concise way to specify a model.
@@ -372,7 +386,7 @@ def override_allow_model_requests(allow_model_requests: bool) -> Iterator[None]:
372
386
  ALLOW_MODEL_REQUESTS = old_value # pyright: ignore[reportConstantRedefinition]
373
387
 
374
388
 
375
- def infer_model(model: Model | KnownModelName) -> Model:
389
+ def infer_model(model: Model | KnownModelName | str) -> Model:
376
390
  """Infer the model from the name."""
377
391
  if isinstance(model, Model):
378
392
  return model
@@ -383,7 +397,6 @@ def infer_model(model: Model | KnownModelName) -> Model:
383
397
 
384
398
  try:
385
399
  provider, model_name = model.split(':', maxsplit=1)
386
- provider = cast(str, provider)
387
400
  except ValueError:
388
401
  model_name = model
389
402
  # TODO(Marcelo): We should deprecate this way.
@@ -431,32 +444,41 @@ def infer_model(model: Model | KnownModelName) -> Model:
431
444
  raise UserError(f'Unknown model: {model}')
432
445
 
433
446
 
434
- def cached_async_http_client(timeout: int = 600, connect: int = 5) -> httpx.AsyncClient:
435
- """Cached HTTPX async client so multiple agents and calls can share the same client.
447
+ def cached_async_http_client(*, provider: str | None = None, timeout: int = 600, connect: int = 5) -> httpx.AsyncClient:
448
+ """Cached HTTPX async client that creates a separate client for each provider.
449
+
450
+ The client is cached based on the provider parameter. If provider is None, it's used for non-provider specific
451
+ requests (like downloading images). Multiple agents and calls can share the same client when they use the same provider.
436
452
 
437
453
  There are good reasons why in production you should use a `httpx.AsyncClient` as an async context manager as
438
454
  described in [encode/httpx#2026](https://github.com/encode/httpx/pull/2026), but when experimenting or showing
439
- examples, it's very useful not to, this allows multiple Agents to use a single client.
455
+ examples, it's very useful not to.
440
456
 
441
457
  The default timeouts match those of OpenAI,
442
458
  see <https://github.com/openai/openai-python/blob/v1.54.4/src/openai/_constants.py#L9>.
443
459
  """
444
- client = _cached_async_http_client(timeout=timeout, connect=connect)
460
+ client = _cached_async_http_client(provider=provider, timeout=timeout, connect=connect)
445
461
  if client.is_closed:
446
462
  # This happens if the context manager is used, so we need to create a new client.
447
463
  _cached_async_http_client.cache_clear()
448
- client = _cached_async_http_client(timeout=timeout, connect=connect)
464
+ client = _cached_async_http_client(provider=provider, timeout=timeout, connect=connect)
449
465
  return client
450
466
 
451
467
 
452
468
  @cache
453
- def _cached_async_http_client(timeout: int = 600, connect: int = 5) -> httpx.AsyncClient:
469
+ def _cached_async_http_client(provider: str | None, timeout: int = 600, connect: int = 5) -> httpx.AsyncClient:
454
470
  return httpx.AsyncClient(
471
+ transport=_cached_async_http_transport(),
455
472
  timeout=httpx.Timeout(timeout=timeout, connect=connect),
456
473
  headers={'User-Agent': get_user_agent()},
457
474
  )
458
475
 
459
476
 
477
+ @cache
478
+ def _cached_async_http_transport() -> httpx.AsyncHTTPTransport:
479
+ return httpx.AsyncHTTPTransport()
480
+
481
+
460
482
  @cache
461
483
  def get_user_agent() -> str:
462
484
  """Get the user agent string for the HTTP client."""
@@ -85,7 +85,10 @@ See [the Anthropic docs](https://docs.anthropic.com/en/docs/about-claude/models)
85
85
 
86
86
 
87
87
  class AnthropicModelSettings(ModelSettings):
88
- """Settings used for an Anthropic model request."""
88
+ """Settings used for an Anthropic model request.
89
+
90
+ ALL FIELDS MUST BE `anthropic_` PREFIXED SO YOU CAN MERGE THEM WITH OTHER MODELS.
91
+ """
89
92
 
90
93
  anthropic_metadata: MetadataParam
91
94
  """An object describing metadata about the request.
@@ -112,6 +112,13 @@ P = ParamSpec('P')
112
112
  T = typing.TypeVar('T')
113
113
 
114
114
 
115
+ class BedrockModelSettings(ModelSettings):
116
+ """Settings for Bedrock models.
117
+
118
+ ALL FIELDS MUST BE `bedrock_` PREFIXED SO YOU CAN MERGE THEM WITH OTHER MODELS.
119
+ """
120
+
121
+
115
122
  @dataclass(init=False)
116
123
  class BedrockConverseModel(Model):
117
124
  """A model that uses the Bedrock Converse API."""
@@ -80,7 +80,10 @@ See [Cohere's docs](https://docs.cohere.com/v2/docs/models) for a list of all av
80
80
 
81
81
 
82
82
  class CohereModelSettings(ModelSettings):
83
- """Settings used for a Cohere model request."""
83
+ """Settings used for a Cohere model request.
84
+
85
+ ALL FIELDS MUST BE `cohere_` PREFIXED SO YOU CAN MERGE THEM WITH OTHER MODELS.
86
+ """
84
87
 
85
88
  # This class is a placeholder for any future cohere-specific settings
86
89
 
@@ -70,7 +70,10 @@ See [the Gemini API docs](https://ai.google.dev/gemini-api/docs/models/gemini#mo
70
70
 
71
71
 
72
72
  class GeminiModelSettings(ModelSettings):
73
- """Settings used for a Gemini model request."""
73
+ """Settings used for a Gemini model request.
74
+
75
+ ALL FIELDS MUST BE `gemini_` PREFIXED SO YOU CAN MERGE THEM WITH OTHER MODELS.
76
+ """
74
77
 
75
78
  gemini_safety_settings: list[GeminiSafetySettings]
76
79
 
@@ -43,34 +43,51 @@ except ImportError as _import_error:
43
43
  'you can use the `groq` optional group — `pip install "pydantic-ai-slim[groq]"`'
44
44
  ) from _import_error
45
45
 
46
-
47
- LatestGroqModelNames = Literal[
46
+ ProductionGroqModelNames = Literal[
47
+ 'distil-whisper-large-v3-en',
48
+ 'gemma2-9b-it',
48
49
  'llama-3.3-70b-versatile',
49
- 'llama-3.3-70b-specdec',
50
50
  'llama-3.1-8b-instant',
51
+ 'llama-guard-3-8b',
52
+ 'llama3-70b-8192',
53
+ 'llama3-8b-8192',
54
+ 'whisper-large-v3',
55
+ 'whisper-large-v3-turbo',
56
+ ]
57
+ """Production Groq models from <https://console.groq.com/docs/models#production-models>."""
58
+
59
+ PreviewGroqModelNames = Literal[
60
+ 'playai-tts',
61
+ 'playai-tts-arabic',
62
+ 'qwen-qwq-32b',
63
+ 'mistral-saba-24b',
64
+ 'qwen-2.5-coder-32b',
65
+ 'qwen-2.5-32b',
66
+ 'deepseek-r1-distill-qwen-32b',
67
+ 'deepseek-r1-distill-llama-70b',
68
+ 'llama-3.3-70b-specdec',
51
69
  'llama-3.2-1b-preview',
52
70
  'llama-3.2-3b-preview',
53
71
  'llama-3.2-11b-vision-preview',
54
72
  'llama-3.2-90b-vision-preview',
55
- 'llama3-70b-8192',
56
- 'llama3-8b-8192',
57
- 'mixtral-8x7b-32768',
58
- 'gemma2-9b-it',
59
73
  ]
60
- """Latest Groq models."""
74
+ """Preview Groq models from <https://console.groq.com/docs/models#preview-models>."""
61
75
 
62
- GroqModelName = Union[str, LatestGroqModelNames]
63
- """
64
- Possible Groq model names.
76
+ GroqModelName = Union[str, ProductionGroqModelNames, PreviewGroqModelNames]
77
+ """Possible Groq model names.
65
78
 
66
- Since Groq supports a variety of date-stamped models, we explicitly list the latest models but
67
- allow any name in the type hints.
68
- See [the Groq docs](https://console.groq.com/docs/models) for a full list.
79
+ Since Groq supports a variety of models and the list changes frequencly, we explicitly list the named models as of 2025-03-31
80
+ but allow any name in the type hints.
81
+
82
+ See <https://console.groq.com/docs/models> for an up to date date list of models and more details.
69
83
  """
70
84
 
71
85
 
72
86
  class GroqModelSettings(ModelSettings):
73
- """Settings used for a Groq model request."""
87
+ """Settings used for a Groq model request.
88
+
89
+ ALL FIELDS MUST BE `groq_` PREFIXED SO YOU CAN MERGE THEM WITH OTHER MODELS.
90
+ """
74
91
 
75
92
  # This class is a placeholder for any future groq-specific settings
76
93
 
@@ -7,7 +7,12 @@ from dataclasses import dataclass, field
7
7
  from typing import Any, Callable, Literal
8
8
  from urllib.parse import urlparse
9
9
 
10
- from opentelemetry._events import Event, EventLogger, EventLoggerProvider, get_event_logger_provider
10
+ from opentelemetry._events import (
11
+ Event, # pyright: ignore[reportPrivateImportUsage]
12
+ EventLogger, # pyright: ignore[reportPrivateImportUsage]
13
+ EventLoggerProvider, # pyright: ignore[reportPrivateImportUsage]
14
+ get_event_logger_provider, # pyright: ignore[reportPrivateImportUsage]
15
+ )
11
16
  from opentelemetry.trace import Span, Tracer, TracerProvider, get_tracer_provider
12
17
  from opentelemetry.util.types import AttributeValue
13
18
  from pydantic import TypeAdapter