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, which names the deployment in its path, OR
deployment_id (with resource_name or AZURE_OPENAI_ENDPOINT). There is
no "azure/<model>" shorthand: Azure serves only the deployments created on
a resource, under whatever names they were given, so a model name does not
identify one.
Source:<builtin>/openai/azure.bamlbytes 1044–11722
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
booltimeout
baml.time.Duration | ai.LlmTimeoutOptions | nullStatic 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; deployment_idwithresource_name, which buildshttps://{resource}.openai.azure.com/openai/deployments/{deployment};deployment_idwithAZURE_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.
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.
Implementations
ai.Client for openai.AzureClient
Instance methods
default_cache_args
(self) -> baml.json.json throws neverWhat a ${cache()} sends as prompt_cache_breakpoint on the part
before it, judged from model by the same rules as
openai.ChatClient: {"mode": "explicit"}, or null for GPT-5.5
and earlier, which reject the field. Azure routes on the
deployment, not model, so this is only as good as model's
name for what the deployment serves.
Provisioned (PTU-M) deployments are not supported: Azure rejects
prompt_cache_breakpoint on them, and nothing here can tell one
from a Standard deployment, so a ${cache()} on a GPT-5.6 PTU-M
deployment is a 400.
id
(self) -> string throws neverinvoke
(render
(Source:<builtin>/openai/azure.bamlbytes 9570–11209
ai.stream.StreamingClient for openai.AzureClient
Instance methods
invoke_stream
(Source:<builtin>/openai/azure.bamlbytes 11215–11720