Azure OpenAI#

Route Azure OpenAI calls through Lockpin so they are priced and capped like any other provider’s. This page is for developers and admins who run OpenAI’s models on their own Azure resource.

How Azure OpenAI works with Lockpin#

Azure hosts OpenAI’s models on your own resource, and its paths name deployments rather than models. Lockpin needs to know where your resource is, and which model each deployment runs, so it can price each call.

Point the Azure SDK at http://127.0.0.1:8787/azure. It sends /azure/openai/deployments/<deployment>/chat/completions?api-version=... as usual, and Lockpin forwards the path and api-version unchanged to your resource. These forms work too:

Form

Path

Deployment (Chat Completions)

/azure/openai/deployments/<deployment>/chat/completions

Responses API

/azure/openai/responses

Azure’s v1 API, model in the body

/azure/openai/v1 or /azure/v1

With the plain OpenAI SDK, use http://127.0.0.1:8787/azure/openai/v1 as the base URL.

Before you begin#

  • Lockpin is installed. See Install.

  • You have an Azure OpenAI resource, its endpoint (https://<resource>.openai.azure.com), and its key, or each agent signs in with Entra ID.

  • You know which model each deployment runs, if a deployment’s name is not its model’s name.

Set up Azure OpenAI#

  1. Set your resource, key and deployment map in the shell that starts Lockpin.

    $env:AZURE_OPENAI_ENDPOINT = "https://<resource>.openai.azure.com"
    $env:AZURE_OPENAI_API_KEY = "..."
    $env:AZURE_OPENAI_DEPLOYMENTS = "prod-chat=gpt-6-sol,cheap=gpt-6-luna"
    lockpin
    
    export AZURE_OPENAI_ENDPOINT=https://<resource>.openai.azure.com
    export AZURE_OPENAI_API_KEY=...
    export AZURE_OPENAI_DEPLOYMENTS=prod-chat=gpt-6-sol,cheap=gpt-6-luna
    lockpin
    

    Variable

    What it holds

    AZURE_OPENAI_ENDPOINT

    Your resource. It must be https, with no credentials, query or fragment; Lockpin refuses anything else.

    AZURE_OPENAI_API_KEY

    The resource’s key. Optional: you can let each agent send its own.

    AZURE_OPENAI_DEPLOYMENTS

    deployment=model pairs, comma-separated, when deployment names are not model names.

  2. Optional: keep the deployment map in a file instead. -azure-deployments FILE takes a JSON object, merged over AZURE_OPENAI_DEPLOYMENTS, and is reloaded with the -prices files:

    {"prod-chat": "gpt-6-sol"}
    
    lockpin -azure-deployments deployments.json
    

    You can also put "deployments" on the azure provider in a -prices file.

  3. Point your agent at Lockpin. With the Azure SDK, set azure_endpoint to Lockpin’s address:

    from openai import AzureOpenAI
    client = AzureOpenAI(azure_endpoint="http://127.0.0.1:8787/azure",
                         api_key="...", api_version="...")
    

Important

AZURE_OPENAI_ENDPOINT is also the Azure SDK’s own variable. Lockpin’s copy must hold your resource, while the agent’s copy points at Lockpin. lockpin run sets the agent’s copy for you. Lockpin refuses an endpoint that is not https, so an inherited http://127.0.0.1:8787/azure can never make it forward to itself.

Keys and sign-in#

  • The agent’s own api-key header, or its Entra ID bearer token (azure_ad_token_provider), is forwarded as sent. Lockpin never requests, refreshes or stores a token.

  • In team mode, a Lockpin key or capability token may sit in the api-key header, as the SDK’s api_key= puts it. See Set up a team.

How deployments are priced#

A deployment is priced as the model it runs. Lockpin looks for it in this order:

  1. The model an earlier reply of that deployment named.

  2. The deployment map: AZURE_OPENAI_DEPLOYMENTS, -azure-deployments FILE, or "deployments" in a -prices file.

  3. The deployment’s own name.

What the deployment runs beats the map, so a wrong map cannot under-reserve for good. Lockpin warns once when they disagree. When a reply names a priced model other than the one reserved, the call is charged at the reply’s model and the ledger says so.

A deployment none of these price is refused with 400 unknown_model, never guessed. -unknown-model-price sends it at a conservative price and alerts, as for any unknown model. See Prices and the price feed.

Note

Prices are OpenAI’s list prices. Azure’s differ by region, so where they do, override the model as "azure/<model>" in a -prices file.

Limits#

  • Embeddings, images and audio are refused unless -allow-uncapped lists their paths, as for OpenAI.

  • Azure cannot be a fallback target yet: fallbacks.json cannot name an azure/ model.

  • Under a signed machine policy, a deployment the map does not resolve is matched against the policy’s model rules by its own name. With -unknown-model-price set, it can pass a deny list once. Keep the map complete.

Verify#

  1. Check the setup, including one HEAD request, with no credentials, to your resource’s host:

    lockpin doctor -network -providers azure
    
  2. Make one Chat Completions call on the deployment form and one on /azure/openai/v1, and check that both appear in the meter at http://127.0.0.1:8787/lockpin/.

  3. Compare the ledger’s cost with Azure’s cost analysis.

A 503 no_endpoint reply means Lockpin has no resource to forward to: set AZURE_OPENAI_ENDPOINT in the shell that starts Lockpin.

Next steps#