pydantic_ai.models
Logic related to making requests to an LLM.
The aim here is to make a common interface for different LLMs, so that the rest of the code can be agnostic to the specific LLM being used.
KnownModelName
module-attribute
KnownModelName = TypeAliasType(
"KnownModelName",
Literal[
"anthropic:claude-3-5-haiku-20241022",
"anthropic:claude-3-5-haiku-latest",
"anthropic:claude-3-7-sonnet-20250219",
"anthropic:claude-3-7-sonnet-latest",
"anthropic:claude-3-haiku-20240307",
"anthropic:claude-3-opus-20240229",
"anthropic:claude-3-opus-latest",
"anthropic:claude-4-opus-20250514",
"anthropic:claude-4-sonnet-20250514",
"anthropic:claude-haiku-4-5",
"anthropic:claude-haiku-4-5-20251001",
"anthropic:claude-opus-4-0",
"anthropic:claude-opus-4-1-20250805",
"anthropic:claude-opus-4-20250514",
"anthropic:claude-opus-4-5",
"anthropic:claude-opus-4-5-20251101",
"anthropic:claude-sonnet-4-0",
"anthropic:claude-sonnet-4-20250514",
"anthropic:claude-sonnet-4-5",
"anthropic:claude-sonnet-4-5-20250929",
"bedrock:amazon.titan-text-express-v1",
"bedrock:amazon.titan-text-lite-v1",
"bedrock:amazon.titan-tg1-large",
"bedrock:anthropic.claude-3-5-haiku-20241022-v1:0",
"bedrock:anthropic.claude-3-5-sonnet-20240620-v1:0",
"bedrock:anthropic.claude-3-5-sonnet-20241022-v2:0",
"bedrock:anthropic.claude-3-7-sonnet-20250219-v1:0",
"bedrock:anthropic.claude-3-haiku-20240307-v1:0",
"bedrock:anthropic.claude-3-opus-20240229-v1:0",
"bedrock:anthropic.claude-3-sonnet-20240229-v1:0",
"bedrock:anthropic.claude-haiku-4-5-20251001-v1:0",
"bedrock:anthropic.claude-instant-v1",
"bedrock:anthropic.claude-opus-4-20250514-v1:0",
"bedrock:anthropic.claude-sonnet-4-20250514-v1:0",
"bedrock:anthropic.claude-sonnet-4-5-20250929-v1:0",
"bedrock:anthropic.claude-v2",
"bedrock:anthropic.claude-v2:1",
"bedrock:cohere.command-light-text-v14",
"bedrock:cohere.command-r-plus-v1:0",
"bedrock:cohere.command-r-v1:0",
"bedrock:cohere.command-text-v14",
"bedrock:eu.anthropic.claude-haiku-4-5-20251001-v1:0",
"bedrock:eu.anthropic.claude-sonnet-4-20250514-v1:0",
"bedrock:eu.anthropic.claude-sonnet-4-5-20250929-v1:0",
"bedrock:global.anthropic.claude-opus-4-5-20251101-v1:0",
"bedrock:meta.llama3-1-405b-instruct-v1:0",
"bedrock:meta.llama3-1-70b-instruct-v1:0",
"bedrock:meta.llama3-1-8b-instruct-v1:0",
"bedrock:meta.llama3-70b-instruct-v1:0",
"bedrock:meta.llama3-8b-instruct-v1:0",
"bedrock:mistral.mistral-7b-instruct-v0:2",
"bedrock:mistral.mistral-large-2402-v1:0",
"bedrock:mistral.mistral-large-2407-v1:0",
"bedrock:mistral.mixtral-8x7b-instruct-v0:1",
"bedrock:us.amazon.nova-lite-v1:0",
"bedrock:us.amazon.nova-micro-v1:0",
"bedrock:us.amazon.nova-pro-v1:0",
"bedrock:us.anthropic.claude-3-5-haiku-20241022-v1:0",
"bedrock:us.anthropic.claude-3-5-sonnet-20240620-v1:0",
"bedrock:us.anthropic.claude-3-5-sonnet-20241022-v2:0",
"bedrock:us.anthropic.claude-3-7-sonnet-20250219-v1:0",
"bedrock:us.anthropic.claude-3-haiku-20240307-v1:0",
"bedrock:us.anthropic.claude-3-opus-20240229-v1:0",
"bedrock:us.anthropic.claude-3-sonnet-20240229-v1:0",
"bedrock:us.anthropic.claude-haiku-4-5-20251001-v1:0",
"bedrock:us.anthropic.claude-opus-4-20250514-v1:0",
"bedrock:us.anthropic.claude-sonnet-4-20250514-v1:0",
"bedrock:us.anthropic.claude-sonnet-4-5-20250929-v1:0",
"bedrock:us.meta.llama3-1-70b-instruct-v1:0",
"bedrock:us.meta.llama3-1-8b-instruct-v1:0",
"bedrock:us.meta.llama3-2-11b-instruct-v1:0",
"bedrock:us.meta.llama3-2-1b-instruct-v1:0",
"bedrock:us.meta.llama3-2-3b-instruct-v1:0",
"bedrock:us.meta.llama3-2-90b-instruct-v1:0",
"bedrock:us.meta.llama3-3-70b-instruct-v1:0",
"cerebras:gpt-oss-120b",
"cerebras:llama-3.3-70b",
"cerebras:llama3.1-8b",
"cerebras:qwen-3-235b-a22b-instruct-2507",
"cerebras:qwen-3-235b-a22b-thinking-2507",
"cerebras:qwen-3-32b",
"cerebras:zai-glm-4.6",
"cohere:c4ai-aya-expanse-32b",
"cohere:c4ai-aya-expanse-8b",
"cohere:command-nightly",
"cohere:command-r-08-2024",
"cohere:command-r-plus-08-2024",
"cohere:command-r7b-12-2024",
"deepseek:deepseek-chat",
"deepseek:deepseek-reasoner",
"gateway/anthropic:claude-3-5-haiku-20241022",
"gateway/anthropic:claude-3-5-haiku-latest",
"gateway/anthropic:claude-3-7-sonnet-20250219",
"gateway/anthropic:claude-3-7-sonnet-latest",
"gateway/anthropic:claude-3-haiku-20240307",
"gateway/anthropic:claude-3-opus-20240229",
"gateway/anthropic:claude-3-opus-latest",
"gateway/anthropic:claude-4-opus-20250514",
"gateway/anthropic:claude-4-sonnet-20250514",
"gateway/anthropic:claude-haiku-4-5",
"gateway/anthropic:claude-haiku-4-5-20251001",
"gateway/anthropic:claude-opus-4-0",
"gateway/anthropic:claude-opus-4-1-20250805",
"gateway/anthropic:claude-opus-4-20250514",
"gateway/anthropic:claude-opus-4-5",
"gateway/anthropic:claude-opus-4-5-20251101",
"gateway/anthropic:claude-sonnet-4-0",
"gateway/anthropic:claude-sonnet-4-20250514",
"gateway/anthropic:claude-sonnet-4-5",
"gateway/anthropic:claude-sonnet-4-5-20250929",
"gateway/bedrock:amazon.titan-text-express-v1",
"gateway/bedrock:amazon.titan-text-lite-v1",
"gateway/bedrock:amazon.titan-tg1-large",
"gateway/bedrock:anthropic.claude-3-5-haiku-20241022-v1:0",
"gateway/bedrock:anthropic.claude-3-5-sonnet-20240620-v1:0",
"gateway/bedrock:anthropic.claude-3-5-sonnet-20241022-v2:0",
"gateway/bedrock:anthropic.claude-3-7-sonnet-20250219-v1:0",
"gateway/bedrock:anthropic.claude-3-haiku-20240307-v1:0",
"gateway/bedrock:anthropic.claude-3-opus-20240229-v1:0",
"gateway/bedrock:anthropic.claude-3-sonnet-20240229-v1:0",
"gateway/bedrock:anthropic.claude-haiku-4-5-20251001-v1:0",
"gateway/bedrock:anthropic.claude-instant-v1",
"gateway/bedrock:anthropic.claude-opus-4-20250514-v1:0",
"gateway/bedrock:anthropic.claude-sonnet-4-20250514-v1:0",
"gateway/bedrock:anthropic.claude-sonnet-4-5-20250929-v1:0",
"gateway/bedrock:anthropic.claude-v2",
"gateway/bedrock:anthropic.claude-v2:1",
"gateway/bedrock:cohere.command-light-text-v14",
"gateway/bedrock:cohere.command-r-plus-v1:0",
"gateway/bedrock:cohere.command-r-v1:0",
"gateway/bedrock:cohere.command-text-v14",
"gateway/bedrock:eu.anthropic.claude-haiku-4-5-20251001-v1:0",
"gateway/bedrock:eu.anthropic.claude-sonnet-4-20250514-v1:0",
"gateway/bedrock:eu.anthropic.claude-sonnet-4-5-20250929-v1:0",
"gateway/bedrock:global.anthropic.claude-opus-4-5-20251101-v1:0",
"gateway/bedrock:meta.llama3-1-405b-instruct-v1:0",
"gateway/bedrock:meta.llama3-1-70b-instruct-v1:0",
"gateway/bedrock:meta.llama3-1-8b-instruct-v1:0",
"gateway/bedrock:meta.llama3-70b-instruct-v1:0",
"gateway/bedrock:meta.llama3-8b-instruct-v1:0",
"gateway/bedrock:mistral.mistral-7b-instruct-v0:2",
"gateway/bedrock:mistral.mistral-large-2402-v1:0",
"gateway/bedrock:mistral.mistral-large-2407-v1:0",
"gateway/bedrock:mistral.mixtral-8x7b-instruct-v0:1",
"gateway/bedrock:us.amazon.nova-lite-v1:0",
"gateway/bedrock:us.amazon.nova-micro-v1:0",
"gateway/bedrock:us.amazon.nova-pro-v1:0",
"gateway/bedrock:us.anthropic.claude-3-5-haiku-20241022-v1:0",
"gateway/bedrock:us.anthropic.claude-3-5-sonnet-20240620-v1:0",
"gateway/bedrock:us.anthropic.claude-3-5-sonnet-20241022-v2:0",
"gateway/bedrock:us.anthropic.claude-3-7-sonnet-20250219-v1:0",
"gateway/bedrock:us.anthropic.claude-3-haiku-20240307-v1:0",
"gateway/bedrock:us.anthropic.claude-3-opus-20240229-v1:0",
"gateway/bedrock:us.anthropic.claude-3-sonnet-20240229-v1:0",
"gateway/bedrock:us.anthropic.claude-haiku-4-5-20251001-v1:0",
"gateway/bedrock:us.anthropic.claude-opus-4-20250514-v1:0",
"gateway/bedrock:us.anthropic.claude-sonnet-4-20250514-v1:0",
"gateway/bedrock:us.anthropic.claude-sonnet-4-5-20250929-v1:0",
"gateway/bedrock:us.meta.llama3-1-70b-instruct-v1:0",
"gateway/bedrock:us.meta.llama3-1-8b-instruct-v1:0",
"gateway/bedrock:us.meta.llama3-2-11b-instruct-v1:0",
"gateway/bedrock:us.meta.llama3-2-1b-instruct-v1:0",
"gateway/bedrock:us.meta.llama3-2-3b-instruct-v1:0",
"gateway/bedrock:us.meta.llama3-2-90b-instruct-v1:0",
"gateway/bedrock:us.meta.llama3-3-70b-instruct-v1:0",
"gateway/google-vertex:gemini-2.0-flash",
"gateway/google-vertex:gemini-2.0-flash-lite",
"gateway/google-vertex:gemini-2.5-flash",
"gateway/google-vertex:gemini-2.5-flash-image",
"gateway/google-vertex:gemini-2.5-flash-lite",
"gateway/google-vertex:gemini-2.5-flash-lite-preview-09-2025",
"gateway/google-vertex:gemini-2.5-flash-preview-09-2025",
"gateway/google-vertex:gemini-2.5-pro",
"gateway/google-vertex:gemini-3-pro-image-preview",
"gateway/google-vertex:gemini-3-pro-preview",
"gateway/google-vertex:gemini-flash-latest",
"gateway/google-vertex:gemini-flash-lite-latest",
"gateway/groq:deepseek-r1-distill-llama-70b",
"gateway/groq:deepseek-r1-distill-qwen-32b",
"gateway/groq:distil-whisper-large-v3-en",
"gateway/groq:gemma2-9b-it",
"gateway/groq:llama-3.1-8b-instant",
"gateway/groq:llama-3.2-11b-vision-preview",
"gateway/groq:llama-3.2-1b-preview",
"gateway/groq:llama-3.2-3b-preview",
"gateway/groq:llama-3.2-90b-vision-preview",
"gateway/groq:llama-3.3-70b-specdec",
"gateway/groq:llama-3.3-70b-versatile",
"gateway/groq:llama-guard-3-8b",
"gateway/groq:llama3-70b-8192",
"gateway/groq:llama3-8b-8192",
"gateway/groq:mistral-saba-24b",
"gateway/groq:moonshotai/kimi-k2-instruct",
"gateway/groq:playai-tts",
"gateway/groq:playai-tts-arabic",
"gateway/groq:qwen-2.5-32b",
"gateway/groq:qwen-2.5-coder-32b",
"gateway/groq:qwen-qwq-32b",
"gateway/groq:whisper-large-v3",
"gateway/groq:whisper-large-v3-turbo",
"gateway/openai:chatgpt-4o-latest",
"gateway/openai:codex-mini-latest",
"gateway/openai:computer-use-preview",
"gateway/openai:computer-use-preview-2025-03-11",
"gateway/openai:gpt-3.5-turbo",
"gateway/openai:gpt-3.5-turbo-0125",
"gateway/openai:gpt-3.5-turbo-0301",
"gateway/openai:gpt-3.5-turbo-0613",
"gateway/openai:gpt-3.5-turbo-1106",
"gateway/openai:gpt-3.5-turbo-16k",
"gateway/openai:gpt-3.5-turbo-16k-0613",
"gateway/openai:gpt-4",
"gateway/openai:gpt-4-0125-preview",
"gateway/openai:gpt-4-0314",
"gateway/openai:gpt-4-0613",
"gateway/openai:gpt-4-1106-preview",
"gateway/openai:gpt-4-32k",
"gateway/openai:gpt-4-32k-0314",
"gateway/openai:gpt-4-32k-0613",
"gateway/openai:gpt-4-turbo",
"gateway/openai:gpt-4-turbo-2024-04-09",
"gateway/openai:gpt-4-turbo-preview",
"gateway/openai:gpt-4-vision-preview",
"gateway/openai:gpt-4.1",
"gateway/openai:gpt-4.1-2025-04-14",
"gateway/openai:gpt-4.1-mini",
"gateway/openai:gpt-4.1-mini-2025-04-14",
"gateway/openai:gpt-4.1-nano",
"gateway/openai:gpt-4.1-nano-2025-04-14",
"gateway/openai:gpt-4o",
"gateway/openai:gpt-4o-2024-05-13",
"gateway/openai:gpt-4o-2024-08-06",
"gateway/openai:gpt-4o-2024-11-20",
"gateway/openai:gpt-4o-audio-preview",
"gateway/openai:gpt-4o-audio-preview-2024-10-01",
"gateway/openai:gpt-4o-audio-preview-2024-12-17",
"gateway/openai:gpt-4o-audio-preview-2025-06-03",
"gateway/openai:gpt-4o-mini",
"gateway/openai:gpt-4o-mini-2024-07-18",
"gateway/openai:gpt-4o-mini-audio-preview",
"gateway/openai:gpt-4o-mini-audio-preview-2024-12-17",
"gateway/openai:gpt-4o-mini-search-preview",
"gateway/openai:gpt-4o-mini-search-preview-2025-03-11",
"gateway/openai:gpt-4o-search-preview",
"gateway/openai:gpt-4o-search-preview-2025-03-11",
"gateway/openai:gpt-5",
"gateway/openai:gpt-5-2025-08-07",
"gateway/openai:gpt-5-chat-latest",
"gateway/openai:gpt-5-codex",
"gateway/openai:gpt-5-mini",
"gateway/openai:gpt-5-mini-2025-08-07",
"gateway/openai:gpt-5-nano",
"gateway/openai:gpt-5-nano-2025-08-07",
"gateway/openai:gpt-5-pro",
"gateway/openai:gpt-5-pro-2025-10-06",
"gateway/openai:gpt-5.1",
"gateway/openai:gpt-5.1-2025-11-13",
"gateway/openai:gpt-5.1-chat-latest",
"gateway/openai:gpt-5.1-codex",
"gateway/openai:gpt-5.1-mini",
"gateway/openai:o1",
"gateway/openai:o1-2024-12-17",
"gateway/openai:o1-mini",
"gateway/openai:o1-mini-2024-09-12",
"gateway/openai:o1-preview",
"gateway/openai:o1-preview-2024-09-12",
"gateway/openai:o1-pro",
"gateway/openai:o1-pro-2025-03-19",
"gateway/openai:o3",
"gateway/openai:o3-2025-04-16",
"gateway/openai:o3-deep-research",
"gateway/openai:o3-deep-research-2025-06-26",
"gateway/openai:o3-mini",
"gateway/openai:o3-mini-2025-01-31",
"gateway/openai:o3-pro",
"gateway/openai:o3-pro-2025-06-10",
"gateway/openai:o4-mini",
"gateway/openai:o4-mini-2025-04-16",
"gateway/openai:o4-mini-deep-research",
"gateway/openai:o4-mini-deep-research-2025-06-26",
"google-gla:gemini-flash-latest",
"google-gla:gemini-flash-lite-latest",
"google-gla:gemini-2.0-flash",
"google-gla:gemini-2.0-flash-lite",
"google-gla:gemini-2.5-flash",
"google-gla:gemini-2.5-flash-preview-09-2025",
"google-gla:gemini-2.5-flash-image",
"google-gla:gemini-2.5-flash-lite",
"google-gla:gemini-2.5-flash-lite-preview-09-2025",
"google-gla:gemini-2.5-pro",
"google-gla:gemini-3-pro-preview",
"google-gla:gemini-3-pro-image-preview",
"google-vertex:gemini-flash-latest",
"google-vertex:gemini-flash-lite-latest",
"google-vertex:gemini-2.0-flash",
"google-vertex:gemini-2.0-flash-lite",
"google-vertex:gemini-2.5-flash",
"google-vertex:gemini-2.5-flash-preview-09-2025",
"google-vertex:gemini-2.5-flash-image",
"google-vertex:gemini-2.5-flash-lite",
"google-vertex:gemini-2.5-flash-lite-preview-09-2025",
"google-vertex:gemini-2.5-pro",
"google-vertex:gemini-3-pro-preview",
"google-vertex:gemini-3-pro-image-preview",
"grok:grok-2-image-1212",
"grok:grok-2-vision-1212",
"grok:grok-3",
"grok:grok-3-fast",
"grok:grok-3-mini",
"grok:grok-3-mini-fast",
"grok:grok-4",
"grok:grok-4-0709",
"grok:grok-4-fast",
"grok:grok-4-fast-reasoning",
"grok:grok-4-fast-non-reasoning",
"grok:grok-code-fast-1",
"grok:grok-4-1-fast",
"grok:grok-4-1-fast-reasoning",
"grok:grok-4-1-fast-non-reasoning",
"groq:deepseek-r1-distill-llama-70b",
"groq:deepseek-r1-distill-qwen-32b",
"groq:distil-whisper-large-v3-en",
"groq:gemma2-9b-it",
"groq:llama-3.1-8b-instant",
"groq:llama-3.2-11b-vision-preview",
"groq:llama-3.2-1b-preview",
"groq:llama-3.2-3b-preview",
"groq:llama-3.2-90b-vision-preview",
"groq:llama-3.3-70b-specdec",
"groq:llama-3.3-70b-versatile",
"groq:llama-guard-3-8b",
"groq:llama3-70b-8192",
"groq:llama3-8b-8192",
"groq:mistral-saba-24b",
"groq:moonshotai/kimi-k2-instruct",
"groq:playai-tts",
"groq:playai-tts-arabic",
"groq:qwen-2.5-32b",
"groq:qwen-2.5-coder-32b",
"groq:qwen-qwq-32b",
"groq:whisper-large-v3",
"groq:whisper-large-v3-turbo",
"heroku:amazon-rerank-1-0",
"heroku:claude-3-5-haiku",
"heroku:claude-3-5-sonnet-latest",
"heroku:claude-3-7-sonnet",
"heroku:claude-3-haiku",
"heroku:claude-4-5-haiku",
"heroku:claude-4-5-sonnet",
"heroku:claude-4-sonnet",
"heroku:cohere-rerank-3-5",
"heroku:gpt-oss-120b",
"heroku:nova-lite",
"heroku:nova-pro",
"huggingface:Qwen/QwQ-32B",
"huggingface:Qwen/Qwen2.5-72B-Instruct",
"huggingface:Qwen/Qwen3-235B-A22B",
"huggingface:Qwen/Qwen3-32B",
"huggingface:deepseek-ai/DeepSeek-R1",
"huggingface:meta-llama/Llama-3.3-70B-Instruct",
"huggingface:meta-llama/Llama-4-Maverick-17B-128E-Instruct",
"huggingface:meta-llama/Llama-4-Scout-17B-16E-Instruct",
"mistral:codestral-latest",
"mistral:mistral-large-latest",
"mistral:mistral-moderation-latest",
"mistral:mistral-small-latest",
"moonshotai:kimi-k2-0711-preview",
"moonshotai:kimi-latest",
"moonshotai:kimi-thinking-preview",
"moonshotai:moonshot-v1-128k",
"moonshotai:moonshot-v1-128k-vision-preview",
"moonshotai:moonshot-v1-32k",
"moonshotai:moonshot-v1-32k-vision-preview",
"moonshotai:moonshot-v1-8k",
"moonshotai:moonshot-v1-8k-vision-preview",
"openai:chatgpt-4o-latest",
"openai:codex-mini-latest",
"openai:computer-use-preview",
"openai:computer-use-preview-2025-03-11",
"openai:gpt-3.5-turbo",
"openai:gpt-3.5-turbo-0125",
"openai:gpt-3.5-turbo-0301",
"openai:gpt-3.5-turbo-0613",
"openai:gpt-3.5-turbo-1106",
"openai:gpt-3.5-turbo-16k",
"openai:gpt-3.5-turbo-16k-0613",
"openai:gpt-4",
"openai:gpt-4-0125-preview",
"openai:gpt-4-0314",
"openai:gpt-4-0613",
"openai:gpt-4-1106-preview",
"openai:gpt-4-32k",
"openai:gpt-4-32k-0314",
"openai:gpt-4-32k-0613",
"openai:gpt-4-turbo",
"openai:gpt-4-turbo-2024-04-09",
"openai:gpt-4-turbo-preview",
"openai:gpt-4-vision-preview",
"openai:gpt-4.1",
"openai:gpt-4.1-2025-04-14",
"openai:gpt-4.1-mini",
"openai:gpt-4.1-mini-2025-04-14",
"openai:gpt-4.1-nano",
"openai:gpt-4.1-nano-2025-04-14",
"openai:gpt-4o",
"openai:gpt-4o-2024-05-13",
"openai:gpt-4o-2024-08-06",
"openai:gpt-4o-2024-11-20",
"openai:gpt-4o-audio-preview",
"openai:gpt-4o-audio-preview-2024-10-01",
"openai:gpt-4o-audio-preview-2024-12-17",
"openai:gpt-4o-audio-preview-2025-06-03",
"openai:gpt-4o-mini",
"openai:gpt-4o-mini-2024-07-18",
"openai:gpt-4o-mini-audio-preview",
"openai:gpt-4o-mini-audio-preview-2024-12-17",
"openai:gpt-4o-mini-search-preview",
"openai:gpt-4o-mini-search-preview-2025-03-11",
"openai:gpt-4o-search-preview",
"openai:gpt-4o-search-preview-2025-03-11",
"openai:gpt-5",
"openai:gpt-5-2025-08-07",
"openai:gpt-5-chat-latest",
"openai:gpt-5-codex",
"openai:gpt-5-mini",
"openai:gpt-5-mini-2025-08-07",
"openai:gpt-5-nano",
"openai:gpt-5-nano-2025-08-07",
"openai:gpt-5-pro",
"openai:gpt-5-pro-2025-10-06",
"openai:gpt-5.1",
"openai:gpt-5.1-2025-11-13",
"openai:gpt-5.1-chat-latest",
"openai:gpt-5.1-codex",
"openai:gpt-5.1-mini",
"openai:o1",
"openai:o1-2024-12-17",
"openai:o1-mini",
"openai:o1-mini-2024-09-12",
"openai:o1-preview",
"openai:o1-preview-2024-09-12",
"openai:o1-pro",
"openai:o1-pro-2025-03-19",
"openai:o3",
"openai:o3-2025-04-16",
"openai:o3-deep-research",
"openai:o3-deep-research-2025-06-26",
"openai:o3-mini",
"openai:o3-mini-2025-01-31",
"openai:o3-pro",
"openai:o3-pro-2025-06-10",
"openai:o4-mini",
"openai:o4-mini-2025-04-16",
"openai:o4-mini-deep-research",
"openai:o4-mini-deep-research-2025-06-26",
"test",
],
)
Known model names that can be used with the model parameter of Agent.
KnownModelName is provided as a concise way to specify a model.
ModelRequestParameters
dataclass
Configuration for an agent's request to a model, specifically related to tools and output handling.
Source code in pydantic_ai_slim/pydantic_ai/models/__init__.py
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | |
Model
Bases: ABC
Abstract class for a model.
Source code in pydantic_ai_slim/pydantic_ai/models/__init__.py
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 | |
__init__
__init__(
*,
settings: ModelSettings | None = None,
profile: ModelProfileSpec | None = None
) -> None
Initialize the model with optional settings and profile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
ModelSettings | None
|
Model-specific settings that will be used as defaults for this model. |
None
|
profile
|
ModelProfileSpec | None
|
The model profile to use. |
None
|
Source code in pydantic_ai_slim/pydantic_ai/models/__init__.py
555 556 557 558 559 560 561 562 563 564 565 566 567 568 | |
request
abstractmethod
async
request(
messages: list[ModelMessage],
model_settings: ModelSettings | None,
model_request_parameters: ModelRequestParameters,
) -> ModelResponse
Make a request to the model.
This is ultimately called by pydantic_ai._agent_graph.ModelRequestNode._make_request(...).
Source code in pydantic_ai_slim/pydantic_ai/models/__init__.py
575 576 577 578 579 580 581 582 583 584 585 586 | |
count_tokens
async
count_tokens(
messages: list[ModelMessage],
model_settings: ModelSettings | None,
model_request_parameters: ModelRequestParameters,
) -> RequestUsage
Make a request to the model for counting tokens.
Source code in pydantic_ai_slim/pydantic_ai/models/__init__.py
588 589 590 591 592 593 594 595 596 | |
request_stream
async
request_stream(
messages: list[ModelMessage],
model_settings: ModelSettings | None,
model_request_parameters: ModelRequestParameters,
run_context: RunContext[Any] | None = None,
) -> AsyncIterator[StreamedResponse]
Make a request to the model and return a streaming response.
Source code in pydantic_ai_slim/pydantic_ai/models/__init__.py
598 599 600 601 602 603 604 605 606 607 608 609 610 611 | |
customize_request_parameters
customize_request_parameters(
model_request_parameters: ModelRequestParameters,
) -> ModelRequestParameters
Customize the request parameters for the model.
This method can be overridden by subclasses to modify the request parameters before sending them to the model. In particular, this method can be used to make modifications to the generated tool JSON schemas if necessary for vendor/model-specific reasons.
Source code in pydantic_ai_slim/pydantic_ai/models/__init__.py
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 | |
prepare_request
prepare_request(
model_settings: ModelSettings | None,
model_request_parameters: ModelRequestParameters,
) -> tuple[ModelSettings | None, ModelRequestParameters]
Prepare request inputs before they are passed to the provider.
This merges the given model_settings with the model's own settings attribute and ensures
customize_request_parameters is applied to the resolved
ModelRequestParameters. Subclasses can override this method if
they need to customize the preparation flow further, but most implementations should simply call
self.prepare_request(...) at the start of their request (and related) methods.
Source code in pydantic_ai_slim/pydantic_ai/models/__init__.py
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 | |
system
abstractmethod
property
system: str
The model provider, ex: openai.
Use to populate the gen_ai.system OpenTelemetry semantic convention attribute,
so should use well-known values listed in
https://opentelemetry.io/docs/specs/semconv/attributes-registry/gen-ai/#gen-ai-system
when applicable.
StreamedResponse
dataclass
Bases: ABC
Streamed response from an LLM when calling a tool.
Source code in pydantic_ai_slim/pydantic_ai/models/__init__.py
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 | |
__aiter__
__aiter__() -> AsyncIterator[ModelResponseStreamEvent]
Stream the response as an async iterable of ModelResponseStreamEvents.
This proxies the _event_iterator() and emits all events, while also checking for matches
on the result schema and emitting a FinalResultEvent if/when the
first match is found.
Source code in pydantic_ai_slim/pydantic_ai/models/__init__.py
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 | |
get
get() -> ModelResponse
Build a ModelResponse from the data received from the stream so far.
Source code in pydantic_ai_slim/pydantic_ai/models/__init__.py
871 872 873 874 875 876 877 878 879 880 881 882 | |
usage
usage() -> RequestUsage
Get the usage of the response so far. This will not be the final usage until the stream is exhausted.
Source code in pydantic_ai_slim/pydantic_ai/models/__init__.py
885 886 887 | |
ALLOW_MODEL_REQUESTS
module-attribute
ALLOW_MODEL_REQUESTS = True
Whether to allow requests to models.
This global setting allows you to disable request to most models, e.g. to make sure you don't accidentally make costly requests to a model during tests.
The testing models TestModel and
FunctionModel are no affected by this setting.
check_allow_model_requests
check_allow_model_requests() -> None
Check if model requests are allowed.
If you're defining your own models that have costs or latency associated with their use, you should call this in
Model.request and Model.request_stream.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If model requests are not allowed. |
Source code in pydantic_ai_slim/pydantic_ai/models/__init__.py
919 920 921 922 923 924 925 926 927 928 929 | |
override_allow_model_requests
Context manager to temporarily override ALLOW_MODEL_REQUESTS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
allow_model_requests
|
bool
|
Whether to allow model requests within the context. |
required |
Source code in pydantic_ai_slim/pydantic_ai/models/__init__.py
932 933 934 935 936 937 938 939 940 941 942 943 944 945 | |