classProvider(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. """_client:InterfaceClient@property@abstractmethoddefname(self)->str:"""The provider name."""raiseNotImplementedError()@property@abstractmethoddefbase_url(self)->str:"""The base URL for the provider API."""raiseNotImplementedError()@property@abstractmethoddefclient(self)->InterfaceClient:"""The client for the provider."""raiseNotImplementedError()
classGoogleVertexProvider(Provider[httpx.AsyncClient]):"""Provider for Vertex AI API."""@propertydefname(self)->str:return'google-vertex'@propertydefbase_url(self)->str:return(f'https://{self.region}-aiplatform.googleapis.com/v1'f'/projects/{self.project_id}'f'/locations/{self.region}'f'/publishers/{self.model_publisher}/models/')@propertydefclient(self)->httpx.AsyncClient:returnself._client@overloaddef__init__(self,*,service_account_file:Path|str|None=None,project_id:str|None=None,region:VertexAiRegion='us-central1',model_publisher:str='google',http_client:httpx.AsyncClient|None=None,)->None:...@overloaddef__init__(self,*,service_account_info:Mapping[str,str]|None=None,project_id:str|None=None,region:VertexAiRegion='us-central1',model_publisher:str='google',http_client:httpx.AsyncClient|None=None,)->None:...def__init__(self,*,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:httpx.AsyncClient|None=None,)->None:"""Create a new Vertex AI provider. Args: service_account_file: Path to a service account file. If not provided, the service_account_info or default environment credentials will be used. service_account_info: The loaded service_account_file contents. If not provided, the service_account_file or default environment credentials will be used. project_id: The project ID to use, if not provided it will be taken from the credentials. region: The region to make requests to. model_publisher: 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 `generateContent` and `streamGenerateContent` functions, hence only `google` is currently supported. Please create an issue or PR if you know how to use other publishers. http_client: An existing `httpx.AsyncClient` to use for making HTTP requests. """ifservice_account_fileandservice_account_info:raiseValueError('Only one of `service_account_file` or `service_account_info` can be provided.')self._client=http_clientorcached_async_http_client(provider='google-vertex')self.service_account_file=service_account_fileself.service_account_info=service_account_infoself.project_id=project_idself.region=regionself.model_publisher=model_publisherself._client.auth=_VertexAIAuth(service_account_file,service_account_info,project_id,region)self._client.base_url=self.base_url
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 generateContent and
streamGenerateContent functions, hence only google is currently supported.
Please create an issue or PR if you know how to use other publishers.
'google'
http_client
AsyncClient | None
An existing httpx.AsyncClient to use for making HTTP requests.
None
Source code in pydantic_ai_slim/pydantic_ai/providers/google_vertex.py
def__init__(self,*,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:httpx.AsyncClient|None=None,)->None:"""Create a new Vertex AI provider. Args: service_account_file: Path to a service account file. If not provided, the service_account_info or default environment credentials will be used. service_account_info: The loaded service_account_file contents. If not provided, the service_account_file or default environment credentials will be used. project_id: The project ID to use, if not provided it will be taken from the credentials. region: The region to make requests to. model_publisher: 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 `generateContent` and `streamGenerateContent` functions, hence only `google` is currently supported. Please create an issue or PR if you know how to use other publishers. http_client: An existing `httpx.AsyncClient` to use for making HTTP requests. """ifservice_account_fileandservice_account_info:raiseValueError('Only one of `service_account_file` or `service_account_info` can be provided.')self._client=http_clientorcached_async_http_client(provider='google-vertex')self.service_account_file=service_account_fileself.service_account_info=service_account_infoself.project_id=project_idself.region=regionself.model_publisher=model_publisherself._client.auth=_VertexAIAuth(service_account_file,service_account_info,project_id,region)self._client.base_url=self.base_url
classOpenAIProvider(Provider[AsyncOpenAI]):"""Provider for OpenAI API."""@propertydefname(self)->str:return'openai'# pragma: no cover@propertydefbase_url(self)->str:returnstr(self.client.base_url)@propertydefclient(self)->AsyncOpenAI:returnself._clientdef__init__(self,base_url:str|None=None,api_key:str|None=None,openai_client:AsyncOpenAI|None=None,http_client:httpx.AsyncClient|None=None,)->None:"""Create a new OpenAI provider. Args: base_url: The base url for the OpenAI requests. If not provided, the `OPENAI_BASE_URL` environment variable will be used if available. Otherwise, defaults to OpenAI's base url. api_key: The API key to use for authentication, if not provided, the `OPENAI_API_KEY` environment variable will be used if available. openai_client: An existing [`AsyncOpenAI`](https://github.com/openai/openai-python?tab=readme-ov-file#async-usage) client to use. If provided, `base_url`, `api_key`, and `http_client` must be `None`. http_client: An existing `httpx.AsyncClient` to use for making HTTP requests. """# This is a workaround for the OpenAI client requiring an API key, whilst locally served,# openai compatible models do not always need an API key, but a placeholder (non-empty) key is required.ifapi_keyisNoneand'OPENAI_API_KEY'notinos.environandbase_urlisnotNoneandopenai_clientisNone:api_key='api-key-not-set'ifopenai_clientisnotNone:assertbase_urlisNone,'Cannot provide both `openai_client` and `base_url`'asserthttp_clientisNone,'Cannot provide both `openai_client` and `http_client`'assertapi_keyisNone,'Cannot provide both `openai_client` and `api_key`'self._client=openai_clientelifhttp_clientisnotNone:self._client=AsyncOpenAI(base_url=base_url,api_key=api_key,http_client=http_client)else:http_client=cached_async_http_client(provider='openai')self._client=AsyncOpenAI(base_url=base_url,api_key=api_key,http_client=http_client)
The base url for the OpenAI requests. If not provided, the OPENAI_BASE_URL environment variable
will be used if available. Otherwise, defaults to OpenAI's base url.
def__init__(self,base_url:str|None=None,api_key:str|None=None,openai_client:AsyncOpenAI|None=None,http_client:httpx.AsyncClient|None=None,)->None:"""Create a new OpenAI provider. Args: base_url: The base url for the OpenAI requests. If not provided, the `OPENAI_BASE_URL` environment variable will be used if available. Otherwise, defaults to OpenAI's base url. api_key: The API key to use for authentication, if not provided, the `OPENAI_API_KEY` environment variable will be used if available. openai_client: An existing [`AsyncOpenAI`](https://github.com/openai/openai-python?tab=readme-ov-file#async-usage) client to use. If provided, `base_url`, `api_key`, and `http_client` must be `None`. http_client: An existing `httpx.AsyncClient` to use for making HTTP requests. """# This is a workaround for the OpenAI client requiring an API key, whilst locally served,# openai compatible models do not always need an API key, but a placeholder (non-empty) key is required.ifapi_keyisNoneand'OPENAI_API_KEY'notinos.environandbase_urlisnotNoneandopenai_clientisNone:api_key='api-key-not-set'ifopenai_clientisnotNone:assertbase_urlisNone,'Cannot provide both `openai_client` and `base_url`'asserthttp_clientisNone,'Cannot provide both `openai_client` and `http_client`'assertapi_keyisNone,'Cannot provide both `openai_client` and `api_key`'self._client=openai_clientelifhttp_clientisnotNone:self._client=AsyncOpenAI(base_url=base_url,api_key=api_key,http_client=http_client)else:http_client=cached_async_http_client(provider='openai')self._client=AsyncOpenAI(base_url=base_url,api_key=api_key,http_client=http_client)
classDeepSeekProvider(Provider[AsyncOpenAI]):"""Provider for DeepSeek API."""@propertydefname(self)->str:return'deepseek'@propertydefbase_url(self)->str:return'https://api.deepseek.com'@propertydefclient(self)->AsyncOpenAI:returnself._client@overloaddef__init__(self)->None:...@overloaddef__init__(self,*,api_key:str)->None:...@overloaddef__init__(self,*,api_key:str,http_client:AsyncHTTPClient)->None:...@overloaddef__init__(self,*,openai_client:AsyncOpenAI|None=None)->None:...def__init__(self,*,api_key:str|None=None,openai_client:AsyncOpenAI|None=None,http_client:AsyncHTTPClient|None=None,)->None:api_key=api_keyoros.getenv('DEEPSEEK_API_KEY')ifnotapi_keyandopenai_clientisNone:raiseUserError('Set the `DEEPSEEK_API_KEY` environment variable or pass it via `DeepSeekProvider(api_key=...)`''to use the DeepSeek provider.')ifopenai_clientisnotNone:self._client=openai_clientelifhttp_clientisnotNone:self._client=AsyncOpenAI(base_url=self.base_url,api_key=api_key,http_client=http_client)else:http_client=cached_async_http_client(provider='deepseek')self._client=AsyncOpenAI(base_url=self.base_url,api_key=api_key,http_client=http_client)
classBedrockProvider(Provider[BaseClient]):"""Provider for AWS Bedrock."""@propertydefname(self)->str:return'bedrock'@propertydefbase_url(self)->str:returnself._client.meta.endpoint_url@propertydefclient(self)->BaseClient:returnself._client@overloaddef__init__(self,*,bedrock_client:BaseClient)->None:...@overloaddef__init__(self,*,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,aws_read_timeout:float|None=None,aws_connect_timeout:float|None=None,)->None:...def__init__(self,*,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,aws_read_timeout:float|None=None,aws_connect_timeout:float|None=None,)->None:"""Initialize the Bedrock provider. Args: bedrock_client: A boto3 client for Bedrock Runtime. If provided, other arguments are ignored. region_name: The AWS region name. aws_access_key_id: The AWS access key ID. aws_secret_access_key: The AWS secret access key. aws_session_token: The AWS session token. aws_read_timeout: The read timeout for Bedrock client. aws_connect_timeout: The connect timeout for Bedrock client. """ifbedrock_clientisnotNone:self._client=bedrock_clientelse:try:read_timeout=aws_read_timeoutorfloat(os.getenv('AWS_READ_TIMEOUT',300))connect_timeout=aws_connect_timeoutorfloat(os.getenv('AWS_CONNECT_TIMEOUT',60))self._client=boto3.client(# type: ignore[reportUnknownMemberType]'bedrock-runtime',aws_access_key_id=aws_access_key_id,aws_secret_access_key=aws_secret_access_key,aws_session_token=aws_session_token,region_name=region_name,config=Config(read_timeout=read_timeout,connect_timeout=connect_timeout),)exceptNoRegionErrorasexc:# pragma: no coverraiseUserError('You must provide a `region_name` or a boto3 client for Bedrock Runtime.')fromexc
def__init__(self,*,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,aws_read_timeout:float|None=None,aws_connect_timeout:float|None=None,)->None:"""Initialize the Bedrock provider. Args: bedrock_client: A boto3 client for Bedrock Runtime. If provided, other arguments are ignored. region_name: The AWS region name. aws_access_key_id: The AWS access key ID. aws_secret_access_key: The AWS secret access key. aws_session_token: The AWS session token. aws_read_timeout: The read timeout for Bedrock client. aws_connect_timeout: The connect timeout for Bedrock client. """ifbedrock_clientisnotNone:self._client=bedrock_clientelse:try:read_timeout=aws_read_timeoutorfloat(os.getenv('AWS_READ_TIMEOUT',300))connect_timeout=aws_connect_timeoutorfloat(os.getenv('AWS_CONNECT_TIMEOUT',60))self._client=boto3.client(# type: ignore[reportUnknownMemberType]'bedrock-runtime',aws_access_key_id=aws_access_key_id,aws_secret_access_key=aws_secret_access_key,aws_session_token=aws_session_token,region_name=region_name,config=Config(read_timeout=read_timeout,connect_timeout=connect_timeout),)exceptNoRegionErrorasexc:# pragma: no coverraiseUserError('You must provide a `region_name` or a boto3 client for Bedrock Runtime.')fromexc
classGroqProvider(Provider[AsyncGroq]):"""Provider for Groq API."""@propertydefname(self)->str:return'groq'@propertydefbase_url(self)->str:returnos.environ.get('GROQ_BASE_URL','https://api.groq.com')@propertydefclient(self)->AsyncGroq:returnself._client@overloaddef__init__(self,*,groq_client:AsyncGroq|None=None)->None:...@overloaddef__init__(self,*,api_key:str|None=None,http_client:AsyncHTTPClient|None=None)->None:...def__init__(self,*,api_key:str|None=None,groq_client:AsyncGroq|None=None,http_client:AsyncHTTPClient|None=None,)->None:"""Create a new Groq provider. Args: api_key: The API key to use for authentication, if not provided, the `GROQ_API_KEY` environment variable will be used if available. groq_client: An existing [`AsyncGroq`](https://github.com/groq/groq-python?tab=readme-ov-file#async-usage) client to use. If provided, `api_key` and `http_client` must be `None`. http_client: An existing `AsyncHTTPClient` to use for making HTTP requests. """ifgroq_clientisnotNone:asserthttp_clientisNone,'Cannot provide both `groq_client` and `http_client`'assertapi_keyisNone,'Cannot provide both `groq_client` and `api_key`'self._client=groq_clientelse:api_key=api_keyoros.environ.get('GROQ_API_KEY')ifnotapi_key:raiseUserError('Set the `GROQ_API_KEY` environment variable or pass it via `GroqProvider(api_key=...)`''to use the Groq provider.')elifhttp_clientisnotNone:self._client=AsyncGroq(base_url=self.base_url,api_key=api_key,http_client=http_client)else:http_client=cached_async_http_client(provider='groq')self._client=AsyncGroq(base_url=self.base_url,api_key=api_key,http_client=http_client)
def__init__(self,*,api_key:str|None=None,groq_client:AsyncGroq|None=None,http_client:AsyncHTTPClient|None=None,)->None:"""Create a new Groq provider. Args: api_key: The API key to use for authentication, if not provided, the `GROQ_API_KEY` environment variable will be used if available. groq_client: An existing [`AsyncGroq`](https://github.com/groq/groq-python?tab=readme-ov-file#async-usage) client to use. If provided, `api_key` and `http_client` must be `None`. http_client: An existing `AsyncHTTPClient` to use for making HTTP requests. """ifgroq_clientisnotNone:asserthttp_clientisNone,'Cannot provide both `groq_client` and `http_client`'assertapi_keyisNone,'Cannot provide both `groq_client` and `api_key`'self._client=groq_clientelse:api_key=api_keyoros.environ.get('GROQ_API_KEY')ifnotapi_key:raiseUserError('Set the `GROQ_API_KEY` environment variable or pass it via `GroqProvider(api_key=...)`''to use the Groq provider.')elifhttp_clientisnotNone:self._client=AsyncGroq(base_url=self.base_url,api_key=api_key,http_client=http_client)else:http_client=cached_async_http_client(provider='groq')self._client=AsyncGroq(base_url=self.base_url,api_key=api_key,http_client=http_client)
classAzureProvider(Provider[AsyncOpenAI]):"""Provider for Azure OpenAI API. See <https://azure.microsoft.com/en-us/products/ai-foundry> for more information. """@propertydefname(self)->str:return'azure'@propertydefbase_url(self)->str:assertself._base_urlisnotNonereturnself._base_url@propertydefclient(self)->AsyncOpenAI:returnself._client@overloaddef__init__(self,*,openai_client:AsyncAzureOpenAI)->None:...@overloaddef__init__(self,*,azure_endpoint:str|None=None,api_version:str|None=None,api_key:str|None=None,http_client:httpx.AsyncClient|None=None,)->None:...def__init__(self,*,azure_endpoint:str|None=None,api_version:str|None=None,api_key:str|None=None,openai_client:AsyncAzureOpenAI|None=None,http_client:httpx.AsyncClient|None=None,)->None:"""Create a new Azure provider. Args: azure_endpoint: The Azure endpoint to use for authentication, if not provided, the `AZURE_OPENAI_ENDPOINT` environment variable will be used if available. api_version: The API version to use for authentication, if not provided, the `OPENAI_API_VERSION` environment variable will be used if available. api_key: The API key to use for authentication, if not provided, the `AZURE_OPENAI_API_KEY` environment variable will be used if available. openai_client: An existing [`AsyncAzureOpenAI`](https://github.com/openai/openai-python#microsoft-azure-openai) client to use. If provided, `base_url`, `api_key`, and `http_client` must be `None`. http_client: An existing `httpx.AsyncClient` to use for making HTTP requests. """ifopenai_clientisnotNone:assertazure_endpointisNone,'Cannot provide both `openai_client` and `azure_endpoint`'asserthttp_clientisNone,'Cannot provide both `openai_client` and `http_client`'assertapi_keyisNone,'Cannot provide both `openai_client` and `api_key`'self._base_url=str(openai_client.base_url)self._client=openai_clientelse:azure_endpoint=azure_endpointoros.getenv('AZURE_OPENAI_ENDPOINT')ifnotazure_endpoint:# pragma: no coverraiseUserError('Must provide one of the `azure_endpoint` argument or the `AZURE_OPENAI_ENDPOINT` environment variable')ifnotapi_keyand'AZURE_OPENAI_API_KEY'notinos.environ:# pragma: no coverraiseUserError('Must provide one of the `api_key` argument or the `AZURE_OPENAI_API_KEY` environment variable')ifnotapi_versionand'OPENAI_API_VERSION'notinos.environ:# pragma: no coverraiseUserError('Must provide one of the `api_version` argument or the `OPENAI_API_VERSION` environment variable')http_client=http_clientorcached_async_http_client(provider='azure')self._client=AsyncAzureOpenAI(azure_endpoint=azure_endpoint,api_key=api_key,api_version=api_version,http_client=http_client,)self._base_url=str(self._client.base_url)
def__init__(self,*,azure_endpoint:str|None=None,api_version:str|None=None,api_key:str|None=None,openai_client:AsyncAzureOpenAI|None=None,http_client:httpx.AsyncClient|None=None,)->None:"""Create a new Azure provider. Args: azure_endpoint: The Azure endpoint to use for authentication, if not provided, the `AZURE_OPENAI_ENDPOINT` environment variable will be used if available. api_version: The API version to use for authentication, if not provided, the `OPENAI_API_VERSION` environment variable will be used if available. api_key: The API key to use for authentication, if not provided, the `AZURE_OPENAI_API_KEY` environment variable will be used if available. openai_client: An existing [`AsyncAzureOpenAI`](https://github.com/openai/openai-python#microsoft-azure-openai) client to use. If provided, `base_url`, `api_key`, and `http_client` must be `None`. http_client: An existing `httpx.AsyncClient` to use for making HTTP requests. """ifopenai_clientisnotNone:assertazure_endpointisNone,'Cannot provide both `openai_client` and `azure_endpoint`'asserthttp_clientisNone,'Cannot provide both `openai_client` and `http_client`'assertapi_keyisNone,'Cannot provide both `openai_client` and `api_key`'self._base_url=str(openai_client.base_url)self._client=openai_clientelse:azure_endpoint=azure_endpointoros.getenv('AZURE_OPENAI_ENDPOINT')ifnotazure_endpoint:# pragma: no coverraiseUserError('Must provide one of the `azure_endpoint` argument or the `AZURE_OPENAI_ENDPOINT` environment variable')ifnotapi_keyand'AZURE_OPENAI_API_KEY'notinos.environ:# pragma: no coverraiseUserError('Must provide one of the `api_key` argument or the `AZURE_OPENAI_API_KEY` environment variable')ifnotapi_versionand'OPENAI_API_VERSION'notinos.environ:# pragma: no coverraiseUserError('Must provide one of the `api_version` argument or the `OPENAI_API_VERSION` environment variable')http_client=http_clientorcached_async_http_client(provider='azure')self._client=AsyncAzureOpenAI(azure_endpoint=azure_endpoint,api_key=api_key,api_version=api_version,http_client=http_client,)self._base_url=str(self._client.base_url)
classCohereProvider(Provider[AsyncClientV2]):"""Provider for Cohere API."""@propertydefname(self)->str:return'cohere'@propertydefbase_url(self)->str:client_wrapper=self.client._client_wrapper# type: ignorereturnstr(client_wrapper.get_base_url())@propertydefclient(self)->AsyncClientV2:returnself._clientdef__init__(self,*,api_key:str|None=None,cohere_client:AsyncClientV2|None=None,http_client:AsyncHTTPClient|None=None,)->None:"""Create a new Cohere provider. Args: api_key: The API key to use for authentication, if not provided, the `CO_API_KEY` environment variable will be used if available. cohere_client: An existing [AsyncClientV2](https://github.com/cohere-ai/cohere-python) client to use. If provided, `api_key` and `http_client` must be `None`. http_client: An existing `httpx.AsyncClient` to use for making HTTP requests. """ifcohere_clientisnotNone:asserthttp_clientisNone,'Cannot provide both `cohere_client` and `http_client`'assertapi_keyisNone,'Cannot provide both `cohere_client` and `api_key`'self._client=cohere_clientelse:api_key=api_keyoros.environ.get('CO_API_KEY')ifnotapi_key:raiseUserError('Set the `CO_API_KEY` environment variable or pass it via `CohereProvider(api_key=...)`''to use the Cohere provider.')base_url=os.environ.get('CO_BASE_URL')ifhttp_clientisnotNone:self._client=AsyncClientV2(api_key=api_key,httpx_client=http_client,base_url=base_url)else:http_client=cached_async_http_client(provider='cohere')self._client=AsyncClientV2(api_key=api_key,httpx_client=http_client,base_url=base_url)
def__init__(self,*,api_key:str|None=None,cohere_client:AsyncClientV2|None=None,http_client:AsyncHTTPClient|None=None,)->None:"""Create a new Cohere provider. Args: api_key: The API key to use for authentication, if not provided, the `CO_API_KEY` environment variable will be used if available. cohere_client: An existing [AsyncClientV2](https://github.com/cohere-ai/cohere-python) client to use. If provided, `api_key` and `http_client` must be `None`. http_client: An existing `httpx.AsyncClient` to use for making HTTP requests. """ifcohere_clientisnotNone:asserthttp_clientisNone,'Cannot provide both `cohere_client` and `http_client`'assertapi_keyisNone,'Cannot provide both `cohere_client` and `api_key`'self._client=cohere_clientelse:api_key=api_keyoros.environ.get('CO_API_KEY')ifnotapi_key:raiseUserError('Set the `CO_API_KEY` environment variable or pass it via `CohereProvider(api_key=...)`''to use the Cohere provider.')base_url=os.environ.get('CO_BASE_URL')ifhttp_clientisnotNone:self._client=AsyncClientV2(api_key=api_key,httpx_client=http_client,base_url=base_url)else:http_client=cached_async_http_client(provider='cohere')self._client=AsyncClientV2(api_key=api_key,httpx_client=http_client,base_url=base_url)
classMistralProvider(Provider[Mistral]):"""Provider for Mistral API."""@propertydefname(self)->str:return'mistral'@propertydefbase_url(self)->str:returnself.client.sdk_configuration.get_server_details()[0]@propertydefclient(self)->Mistral:returnself._client@overloaddef__init__(self,*,mistral_client:Mistral|None=None)->None:...@overloaddef__init__(self,*,api_key:str|None=None,http_client:AsyncHTTPClient|None=None)->None:...def__init__(self,*,api_key:str|None=None,mistral_client:Mistral|None=None,base_url:str|None=None,http_client:AsyncHTTPClient|None=None,)->None:"""Create a new Mistral provider. Args: api_key: The API key to use for authentication, if not provided, the `MISTRAL_API_KEY` environment variable will be used if available. mistral_client: An existing `Mistral` client to use, if provided, `api_key` and `http_client` must be `None`. base_url: The base url for the Mistral requests. http_client: An existing async client to use for making HTTP requests. """ifmistral_clientisnotNone:asserthttp_clientisNone,'Cannot provide both `mistral_client` and `http_client`'assertapi_keyisNone,'Cannot provide both `mistral_client` and `api_key`'assertbase_urlisNone,'Cannot provide both `mistral_client` and `base_url`'self._client=mistral_clientelse:api_key=api_keyoros.environ.get('MISTRAL_API_KEY')ifnotapi_key:raiseUserError('Set the `MISTRAL_API_KEY` environment variable or pass it via `MistralProvider(api_key=...)`''to use the Mistral provider.')elifhttp_clientisnotNone:self._client=Mistral(api_key=api_key,async_client=http_client,server_url=base_url)else:http_client=cached_async_http_client(provider='mistral')self._client=Mistral(api_key=api_key,async_client=http_client,server_url=base_url)
def__init__(self,*,api_key:str|None=None,mistral_client:Mistral|None=None,base_url:str|None=None,http_client:AsyncHTTPClient|None=None,)->None:"""Create a new Mistral provider. Args: api_key: The API key to use for authentication, if not provided, the `MISTRAL_API_KEY` environment variable will be used if available. mistral_client: An existing `Mistral` client to use, if provided, `api_key` and `http_client` must be `None`. base_url: The base url for the Mistral requests. http_client: An existing async client to use for making HTTP requests. """ifmistral_clientisnotNone:asserthttp_clientisNone,'Cannot provide both `mistral_client` and `http_client`'assertapi_keyisNone,'Cannot provide both `mistral_client` and `api_key`'assertbase_urlisNone,'Cannot provide both `mistral_client` and `base_url`'self._client=mistral_clientelse:api_key=api_keyoros.environ.get('MISTRAL_API_KEY')ifnotapi_key:raiseUserError('Set the `MISTRAL_API_KEY` environment variable or pass it via `MistralProvider(api_key=...)`''to use the Mistral provider.')elifhttp_clientisnotNone:self._client=Mistral(api_key=api_key,async_client=http_client,server_url=base_url)else:http_client=cached_async_http_client(provider='mistral')self._client=Mistral(api_key=api_key,async_client=http_client,server_url=base_url)