polygate logopolygate

Cloud

Azure OpenAI

OpenAI models on your own Azure resource.

Quick start

import polygate
 
response = polygate.chat(
provider="azure",
base_url="...",
model="your-deployment-name",
messages=[{"role": "user", "content": "Say hi in one word."}],
)
 
print(response.content) # "Hi!"
print(response.usage) # Usage(prompt_tokens=..., completion_tokens=...)

Names

Any of these work as provider. They all reach the same adapter, so pick whichever reads best in your code.

azureazure_openai

Configuration

VariableHolds
AZURE_OPENAI_API_KEYyour API key
AZURE_OPENAI_ENDPOINTyour resource host, e.g. https://my-resource.openai.azure.com
AZURE_OPENAI_API_VERSIONoverrides the pinned default

Any of these may hold a comma-separated list. polygate rotates across them, parks a rate-limited one for its Retry-After, and drops one the provider rejects — so a key pool is configuration, not code.

Endpoint

There is no fixed host: the URL contains your own account, workspace or project, so base_url is required. Omit it and polygate raises MissingEndpointError naming the variable to set, rather than letting the request fail somewhere less informative.

Models

Examples that work today. Model names change; the provider's own list is the authority.

your-deployment-name

Things worth knowing

  • The `model` is your deployment name, not a vendor model id. Your deployment can be called anything, so model: "gpt-4o" only works if you named the deployment gpt-4o.
  • The key goes in an api-key header, not as a Bearer token. Sending a Bearer token returns a 401 that is indistinguishable from a wrong key — polygate handles this for you.
  • An api-version query parameter is mandatory; omitting it is a 404. polygate pins a known-good version rather than tracking latest, because Azure's versions change model behaviour and a drifting default would turn a library upgrade into a silent change in output.

Batch

Azure OpenAI has no offline batch API. To run many requests at once, use map_chat — full price, but it works everywhere and returns in seconds. See Batching & concurrency.

Something wrong or missing here? Open an issue.