pydantic_ai.providers
Bases: ABC
, Generic[InterfaceClient]
Abstract class for a provider.
The provider is in charge of providing an authenticated client to the API.
Each provider only supports a specific interface. A interface can be supported by multiple providers.
For example, the OpenAIModel interface can be supported by the OpenAIProvider and the DeepSeekProvider.
Source code in pydantic_ai_slim/pydantic_ai/providers/__init__.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
GoogleProvider
Bases: Provider[Client]
Provider for Google.
Source code in pydantic_ai_slim/pydantic_ai/providers/google.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
__init__
__init__(*, api_key: str) -> None
__init__(
*,
credentials: Credentials | None = None,
project: str | None = None,
location: (
VertexAILocation | Literal["global"] | None
) = None
) -> None
__init__(*, client: Client) -> None
__init__(*, vertexai: bool = False) -> None
__init__(
*,
api_key: str | None = None,
credentials: Credentials | None = None,
project: str | None = None,
location: (
VertexAILocation | Literal["global"] | None
) = None,
client: Client | None = None,
vertexai: bool | None = None
) -> None
Create a new Google provider.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_key
|
str | None
|
The |
None
|
credentials
|
Credentials | None
|
The credentials to use for authentication when calling the Vertex AI APIs. Credentials can be obtained from environment variables and default credentials. For more information, see Set up Application Default Credentials. Applies to the Vertex AI API only. |
None
|
project
|
str | None
|
The Google Cloud project ID to use for quota. Can be obtained from environment variables (for example, GOOGLE_CLOUD_PROJECT). Applies to the Vertex AI API only. |
None
|
location
|
VertexAILocation | Literal['global'] | None
|
The location to send API requests to (for example, us-central1). Can be obtained from environment variables. Applies to the Vertex AI API only. |
None
|
client
|
Client | None
|
A pre-initialized client to use. |
None
|
vertexai
|
bool | None
|
Force the use of the Vertex AI API. If |
None
|
Source code in pydantic_ai_slim/pydantic_ai/providers/google.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
VertexAILocation
module-attribute
VertexAILocation = Literal[
"asia-east1",
"asia-east2",
"asia-northeast1",
"asia-northeast3",
"asia-south1",
"asia-southeast1",
"australia-southeast1",
"europe-central2",
"europe-north1",
"europe-southwest1",
"europe-west1",
"europe-west2",
"europe-west3",
"europe-west4",
"europe-west6",
"europe-west8",
"europe-west9",
"me-central1",
"me-central2",
"me-west1",
"northamerica-northeast1",
"southamerica-east1",
"us-central1",
"us-east1",
"us-east4",
"us-east5",
"us-south1",
"us-west1",
"us-west4",
]
Regions available for Vertex AI. More details here.
GoogleVertexProvider
Bases: Provider[AsyncClient]
Provider for Vertex AI API.
Source code in pydantic_ai_slim/pydantic_ai/providers/google_vertex.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
__init__
__init__(
*,
service_account_file: Path | str | None = None,
service_account_info: Mapping[str, str] | None = None,
project_id: str | None = None,
region: VertexAiRegion = "us-central1",
model_publisher: str = "google",
http_client: AsyncClient | None = None
) -> None
Create a new Vertex AI provider.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service_account_file
|
Path | str | None
|
Path to a service account file. If not provided, the service_account_info or default environment credentials will be used. |
None
|
service_account_info
|
Mapping[str, str] | None
|
The loaded service_account_file contents. If not provided, the service_account_file or default environment credentials will be used. |
None
|
project_id
|
str | None
|
The project ID to use, if not provided it will be taken from the credentials. |
None
|
region
|
VertexAiRegion
|
The region to make requests to. |
'us-central1'
|
model_publisher
|
str
|
The model publisher to use, I couldn't find a good list of available publishers,
and from trial and error it seems non-google models don't work with the |
'google'
|
http_client
|
AsyncClient | None
|
An existing |
None
|
Source code in pydantic_ai_slim/pydantic_ai/providers/google_vertex.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
OpenAIProvider
Bases: Provider[AsyncOpenAI]
Provider for OpenAI API.
Source code in pydantic_ai_slim/pydantic_ai/providers/openai.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
__init__
__init__(
base_url: str | None = None,
api_key: str | None = None,
openai_client: AsyncOpenAI | None = None,
http_client: AsyncClient | None = None,
) -> None
Create a new OpenAI provider.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_url
|
str | None
|
The base url for the OpenAI requests. If not provided, the |
None
|
api_key
|
str | None
|
The API key to use for authentication, if not provided, the |
None
|
openai_client
|
AsyncOpenAI | None
|
An existing
|
None
|
http_client
|
AsyncClient | None
|
An existing |
None
|
Source code in pydantic_ai_slim/pydantic_ai/providers/openai.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
DeepSeekProvider
Bases: Provider[AsyncOpenAI]
Provider for DeepSeek API.
Source code in pydantic_ai_slim/pydantic_ai/providers/deepseek.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
BedrockProvider
Bases: Provider[BaseClient]
Provider for AWS Bedrock.
Source code in pydantic_ai_slim/pydantic_ai/providers/bedrock.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
__init__
__init__(*, bedrock_client: BaseClient) -> None
__init__(
*,
bedrock_client: BaseClient | None = None,
region_name: str | None = None,
aws_access_key_id: str | None = None,
aws_secret_access_key: str | None = None,
aws_session_token: str | None = None,
profile_name: str | None = None,
aws_read_timeout: float | None = None,
aws_connect_timeout: float | None = None
) -> None
Initialize the Bedrock provider.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bedrock_client
|
BaseClient | None
|
A boto3 client for Bedrock Runtime. If provided, other arguments are ignored. |
None
|
region_name
|
str | None
|
The AWS region name. |
None
|
aws_access_key_id
|
str | None
|
The AWS access key ID. |
None
|
aws_secret_access_key
|
str | None
|
The AWS secret access key. |
None
|
aws_session_token
|
str | None
|
The AWS session token. |
None
|
profile_name
|
str | None
|
The AWS profile name. |
None
|
aws_read_timeout
|
float | None
|
The read timeout for Bedrock client. |
None
|
aws_connect_timeout
|
float | None
|
The connect timeout for Bedrock client. |
None
|
Source code in pydantic_ai_slim/pydantic_ai/providers/bedrock.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
GroqProvider
Bases: Provider[AsyncGroq]
Provider for Groq API.
Source code in pydantic_ai_slim/pydantic_ai/providers/groq.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
__init__
__init__(*, groq_client: AsyncGroq | None = None) -> None
__init__(
*,
api_key: str | None = None,
http_client: AsyncClient | None = None
) -> None
__init__(
*,
api_key: str | None = None,
groq_client: AsyncGroq | None = None,
http_client: AsyncClient | None = None
) -> None
Create a new Groq provider.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_key
|
str | None
|
The API key to use for authentication, if not provided, the |
None
|
groq_client
|
AsyncGroq | None
|
An existing
|
None
|
http_client
|
AsyncClient | None
|
An existing |
None
|
Source code in pydantic_ai_slim/pydantic_ai/providers/groq.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
AzureProvider
Bases: Provider[AsyncOpenAI]
Provider for Azure OpenAI API.
See https://azure.microsoft.com/en-us/products/ai-foundry for more information.
Source code in pydantic_ai_slim/pydantic_ai/providers/azure.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
__init__
__init__(*, openai_client: AsyncAzureOpenAI) -> None
__init__(
*,
azure_endpoint: str | None = None,
api_version: str | None = None,
api_key: str | None = None,
openai_client: AsyncAzureOpenAI | None = None,
http_client: AsyncClient | None = None
) -> None
Create a new Azure provider.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
azure_endpoint
|
str | None
|
The Azure endpoint to use for authentication, if not provided, the |
None
|
api_version
|
str | None
|
The API version to use for authentication, if not provided, the |
None
|
api_key
|
str | None
|
The API key to use for authentication, if not provided, the |
None
|
openai_client
|
AsyncAzureOpenAI | None
|
An existing
|
None
|
http_client
|
AsyncClient | None
|
An existing |
None
|
Source code in pydantic_ai_slim/pydantic_ai/providers/azure.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
CohereProvider
Bases: Provider[AsyncClientV2]
Provider for Cohere API.
Source code in pydantic_ai_slim/pydantic_ai/providers/cohere.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
__init__
__init__(
*,
api_key: str | None = None,
cohere_client: AsyncClientV2 | None = None,
http_client: AsyncClient | None = None
) -> None
Create a new Cohere provider.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_key
|
str | None
|
The API key to use for authentication, if not provided, the |
None
|
cohere_client
|
AsyncClientV2 | None
|
An existing
AsyncClientV2
client to use. If provided, |
None
|
http_client
|
AsyncClient | None
|
An existing |
None
|
Source code in pydantic_ai_slim/pydantic_ai/providers/cohere.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
MistralProvider
Bases: Provider[Mistral]
Provider for Mistral API.
Source code in pydantic_ai_slim/pydantic_ai/providers/mistral.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
__init__
__init__(*, mistral_client: Mistral | None = None) -> None
__init__(
*,
api_key: str | None = None,
http_client: AsyncClient | None = None
) -> None
__init__(
*,
api_key: str | None = None,
mistral_client: Mistral | None = None,
base_url: str | None = None,
http_client: AsyncClient | None = None
) -> None
Create a new Mistral provider.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_key
|
str | None
|
The API key to use for authentication, if not provided, the |
None
|
mistral_client
|
Mistral | None
|
An existing |
None
|
base_url
|
str | None
|
The base url for the Mistral requests. |
None
|
http_client
|
AsyncClient | None
|
An existing async client to use for making HTTP requests. |
None
|
Source code in pydantic_ai_slim/pydantic_ai/providers/mistral.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|