openai.AzureClient

Azure OpenAI Service chat completions.

Reference version

Signature

class openai.AzureClient

Azure 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-key header, not Authorization: Bearer;
  • a token ceiling is effectively mandatory, so 4096 is injected when the caller set neither max_tokens nor max_completion_tokens (including through request_body). Passing request_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 78710381

Fields

model

string

resource_name

string | null

deployment_id

string | null

api_version

string | null

base_url

ai.Credential | null

api_key

ai.Credential | null

request_body

baml.json.json | null

headers

map<string, string> | null

query_params

map<string, string> | null

temperature

float | null

max_tokens

int | null

max_completion_tokens

int | null

top_p

float | null

stop

string[] | null

seed

int | null

capture_wire

bool

Static methods

function

new

(
model: string,
resource_name: string | null = …,
deployment_id: string | null = …,
api_version: string | null = …,
base_url: ai.Credential | null = …,
api_key: ai.Credential | null = …,
request_body: baml.json.json | null = …,
headers: map<string, string> | null = …,
query_params: map<string, string> | null = …,
temperature: float | null = …,
max_tokens: int | null = …,
max_completion_tokens: int | null = …,
top_p: float | null = …,
stop: string[] | null = …,
seed: int | null = …,
capture_wire: bool = …
) -> openai.AzureClient

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

function

compat

(
self
) -> openai.internal.ChatCompat throws baml.errors.Io | baml.errors.ParseError | ai.errors.InvalidRequest

The provider record: everything the shared chat core needs to know about this endpoint.

function

params

(
self,
preview: bool = …
) -> openai.internal.ChatParams throws baml.errors.Io | baml.errors.ParseError

The per-request parameters handed to the shared chat core.

Parameters

  • preview: omit the credential, for rendering a request without sending it.
function

resolved_api_key

(self) -> string | null throws baml.errors.Io | baml.errors.ParseError

The 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.

function

resolved_base_url

(
self
) -> string throws baml.errors.Io | baml.errors.ParseError | ai.errors.InvalidRequest

The deployment base this client posts to, resolved in the order Azure users actually configure things:

  1. an explicit base_url (a literal or an env.NAME ref), used verbatim — it already names the deployment;
  2. resource_name, which builds https://{resource}.openai.azure.com/openai/deployments/{deployment};
  3. 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.

function

resolved_deployment_id

(self) -> string

The deployment segment: the caller's deployment_id, else the model.

Implementations

ai.Client for openai.AzureClient

Instance methods

function

id

(self) -> string
function

invoke

(
self,
input: ai.ModelTurnInput
) -> ai.ModelTurn throws baml.errors.Timeout | baml.errors.UnknownError | reflect.errors.CompilationError | ai.errors.Failure
function

render

(
self,
input: ai.ModelTurnInput
) -> baml.http.Request throws baml.errors.Timeout | baml.errors.UnknownError | reflect.errors.CompilationError | ai.errors.Failure

Source:<builtin>/openai/azure.bamlbytes 92139947

ai.stream.StreamingClient for openai.AzureClient

Instance methods

function

invoke_stream

(
self,
input: ai.ModelTurnInput
) -> ai.stream.TurnStream throws baml.errors.Timeout | baml.errors.UnknownError | reflect.errors.CompilationError | ai.errors.Failure

Source:<builtin>/openai/azure.bamlbytes 995310379