openai.AzureClient
Azure OpenAI Service chat completions.
Signature
class openai.AzureClientAzure OpenAI Service chat completions.
Azure differs from OpenAI in three ways, all of them config:
- the deployment is part of the URL —
https://{resource_name}.openai.azure.com/openai/deployments/{deployment_id}/chat/completions— with the API version as a query parameter; - the credential rides in an
api-keyheader, notAuthorization: Bearer; - a token ceiling is effectively mandatory, so 4096 is injected when the
caller set neither
max_tokensnormax_completion_tokens(including throughrequest_body). Passingrequest_body = {"max_tokens": null}removes it again — the merge runs after the default is applied.
Supply either base_url OR both resource_name and deployment_id.
Source:<builtin>/openai/azure.bamlbytes 787–10381
Fields
model
stringresource_name
string | nulldeployment_id
string | nullapi_version
string | nullbase_url
ai.Credential | nullapi_key
ai.Credential | nullrequest_body
baml.json.json | nullheaders
map<string, string> | nullquery_params
map<string, string> | nulltemperature
float | nullmax_tokens
int | nullmax_completion_tokens
int | nulltop_p
float | nullstop
string[] | nullseed
int | nullcapture_wire
boolStatic methods
new
(Creates a client. Construction reads no environment variable, so declaring one is always safe; credentials and endpoints resolve when a request is built.
Instance methods
compat
(The provider record: everything the shared chat core needs to know about this endpoint.
params
(The per-request parameters handed to the shared chat core.
Parameters
preview: omit the credential, for rendering a request without sending it.
resolved_api_key
(self) -> string | null throws baml.errors.Io | baml.errors.ParseErrorThe request-time credential: the explicit value, else
AZURE_OPENAI_API_KEY. Azure sends it in an api-key header rather
than as a bearer token.
resolved_base_url
(The deployment base this client posts to, resolved in the order Azure users actually configure things:
- an explicit
base_url(a literal or anenv.NAMEref), used verbatim — it already names the deployment; resource_name, which buildshttps://{resource}.openai.azure.com/openai/deployments/{deployment};AZURE_OPENAI_ENDPOINT— the variable the official Azure OpenAI SDKs read — treated as the resource ORIGIN and given the same/openai/deployments/{deployment}path as rung 2.
Rung 3 is what makes the "azure/<model>" shorthand viable. The
shorthand can only supply a model, and every other provider's shorthand
works off ambient credentials; without an endpoint fallback this client
could never send. With deployment_id defaulting to model, ambient
AZURE_OPENAI_ENDPOINT + AZURE_OPENAI_API_KEY is a complete config.
The engine reports the mutually-exclusive shapes at compile time with per-key spans; a BAML constructor can only report at request time, so the error names every source that was checked.
resolved_deployment_id
(self) -> stringThe deployment segment: the caller's deployment_id, else the model.
Implementations
ai.Client for openai.AzureClient
Instance methods
id
(self) -> stringinvoke
(render
(Source:<builtin>/openai/azure.bamlbytes 9213–9947
ai.stream.StreamingClient for openai.AzureClient
Instance methods
invoke_stream
(Source:<builtin>/openai/azure.bamlbytes 9953–10379