Azure AI Foundry¶
An openai-compat subclass carrying Azure's parameter renames and
its two authentication modes.
Setup¶
client = ai.Client(
[
ai.ProviderSettings.of(
"azure-foundry",
base_url="https://<resource>.services.ai.azure.com/openai/v1",
api_key="env://AZURE_AI_KEY",
),
]
)
result = client.generate(prompt, target="azure-foundry:gpt-5")
pip install "anyinfer[azure]"
az login
ai.ProviderSettings.of(
"azure-foundry",
base_url="https://<resource>.services.ai.azure.com/openai/v1",
# no api_key: DefaultAzureCredential is used
)
Aliases: azure, foundry.
Differences from openai-compat¶
| Azure | |
|---|---|
| Output-token parameter | max_completion_tokens |
| Reasoning effort | flat reasoning_effort field |
| Auth header | api-key, or Authorization: Bearer for Entra |
| API version | optional api-version query parameter |
Sending max_tokens to Azure is rejected outright, which is why the subclass exists.
API Versions¶
ai.ProviderSettings.of("azure-foundry", base_url=..., api_version="2024-10-21")
Only needed for deployments that still require it; the newer /openai/v1 surface does not.
Chat, embeddings, and model listing all carry it consistently.
Embeddings¶
result = client.embed(
["first text", "second text"],
target="azure-foundry:text-embedding-3-small",
)
target's model half is the deployment name, not necessarily the underlying model's
catalog id. The same POST {base_url}/embeddings surface as chat (deployment-less on
/openai/v1, or api-version-pinned on the older surface) speaks the identical
OpenAI-compatible body.
Azure documents the same request ceilings OpenAI itself does: 2,048 inputs per request, 8,192 tokens per input, and 300,000 tokens aggregate. Since the deployment name is tenant-chosen, AnyInfer does not declare these as static per-model capabilities; a request larger than what the deployment accepts surfaces as a provider error rather than a pre-flight refusal.
Troubleshooting¶
could not acquire an Entra token: run az login, or configure a service principal in
the environment. The error names the scope it tried.
azure-foundry requires the base URL of your Foundry resource: the resource endpoint
is deployment-specific and cannot be defaulted.
Wire Contract¶
For the exact request/response fields this adapter depends on, see contracts/azure-foundry.md.