docs/azure-openai.md
CodexBar's Azure OpenAI provider validates that a configured deployment is reachable. It does not read Azure spend, quota history, or token usage history.
Azure OpenAI requires three values:
Settings -> Providers -> Azure OpenAI stores those values in the shared CodexBar config. The same values can also be provided with environment variables:
export AZURE_OPENAI_API_KEY="..."
export AZURE_OPENAI_ENDPOINT="https://resource.openai.azure.com"
export AZURE_OPENAI_DEPLOYMENT_NAME="chat-prod"
You can store the API key through the CLI:
printf '%s' "$AZURE_OPENAI_API_KEY" | codexbar config set-api-key --provider azure-openai --stdin
The endpoint and deployment are stored as enterpriseHost and workspaceID in the azureopenai provider config:
{
"id": "azureopenai",
"apiKey": "<AZURE_OPENAI_API_KEY>",
"enterpriseHost": "https://resource.openai.azure.com",
"workspaceID": "chat-prod"
}
CodexBar sends a minimal chat-completions request to validate the deployment:
POST https://resource.openai.azure.com/openai/deployments/<deployment>/chat/completions?api-version=2024-10-21
api-key: <api key>
Accept: application/json
Content-Type: application/json
For dated API versions, the request body contains one ping message and max_tokens: 1. A successful response is
parsed only for the returned model field so the menu can show deployment detail.
Set AZURE_OPENAI_API_VERSION to override the API version. When it is set to v1, CodexBar uses Azure's
OpenAI-compatible v1 path, includes the deployment name as the request model, and uses
max_completion_tokens: 1:
POST https://resource.openai.azure.com/openai/v1/chat/completions
AZURE_OPENAI_ENDPOINT and the configured endpoint field must be HTTPS URLs, or bare hosts that can be normalized to
HTTPS. CodexBar rejects explicit http:// endpoints, user info, and encoded host-delimiter tricks before attaching the
api-key header.
Endpoint paths are preserved. CodexBar avoids duplicating a trailing /openai for dated API versions or a trailing
/openai/v1 for the v1 API when building the validation URL.
Each refresh with complete, valid configuration sends this real inference request and can consume billable input and output tokens for the configured deployment.
api label before a fetch. After a successful fetch, Settings' Source row and
the CLI report deployment.Deployment: <name> and includes Model: <model> when the validation response returns
one.codexbar usage --provider azure-openai
codexbar usage --provider azureopenai
codexbar usage --provider aoai
Sources/CodexBarCore/Providers/AzureOpenAI/AzureOpenAIProviderDescriptor.swiftSources/CodexBarCore/Providers/AzureOpenAI/AzureOpenAISettingsReader.swiftSources/CodexBarCore/Providers/AzureOpenAI/AzureOpenAIUsageFetcher.swiftSources/CodexBar/Providers/AzureOpenAI/AzureOpenAIProviderImplementation.swiftTests/CodexBarTests/AzureOpenAIUsageFetcherTests.swift