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 |
|
GoogleVertexProvider
Bases: Provider[AsyncClient]
Provider for Vertex AI API.
Source code in pydantic_ai_slim/pydantic_ai/providers/google_vertex.py
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 109 |
|
__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
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 109 |
|
OpenAIProvider
Bases: Provider[AsyncOpenAI]
Provider for OpenAI API.
Source code in pydantic_ai_slim/pydantic_ai/providers/openai.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 |
|
__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
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 |
|
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 |
|
BedrockProvider
Bases: Provider[BaseClient]
Provider for AWS Bedrock.
Source code in pydantic_ai_slim/pydantic_ai/providers/bedrock.py
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 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__(*, 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
) -> 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
|
Source code in pydantic_ai_slim/pydantic_ai/providers/bedrock.py
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 |
|
GroqProvider
Bases: Provider[AsyncGroq]
Provider for Groq API.
Source code in pydantic_ai_slim/pydantic_ai/providers/groq.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 |
|
__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
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 |
|
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
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 108 |
|
__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
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 |
|