Dashboard Get started

Usage

from tokenid import JournaledAzureOpenAI

client = JournaledAzureOpenAI(
    azure_endpoint="https://my-resource.openai.azure.com",
    api_version="2024-02-01",
    session_id="my-session",
)

resp = client.chat.completions.create(
    model="my-gpt4-deployment",     # deployment name, NOT a canonical model name
    messages=[{"role": "user", "content": "Hello"}],
)

JournaledAzureOpenAI accepts every constructor argument that openai.AzureOpenAI accepts — azure_endpoint, api_version, azure_deployment, api_key, and so on — and forwards every method call to the underlying client. The API key is read from the AZURE_OPENAI_API_KEY environment variable by default, or pass api_key= explicitly.

Azure OpenAI uses **deployment names** as the `model` parameter, not canonical model names. The string you pass as `model=` must match a deployment you created in Azure AI Studio, e.g. `"my-gpt4-deployment"` — not `"gpt-4o"`. Any `ModelCeiling` or routing enforcer that rewrites `model` must also use a deployment name as the target value. A rewritten value that does not match any deployed resource will cause the API call to fail.

Streaming

stream = client.chat.completions.create(
    model="my-gpt4-deployment",
    messages=[{"role": "user", "content": "Hello"}],
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="", flush=True)

Token counts are aggregated across the final stream chunk and journaled on completion.

Async

Use AsyncJournaledAzureOpenAI for async code:

import asyncio
from tokenid import AsyncJournaledAzureOpenAI

async def main():
    client = AsyncJournaledAzureOpenAI(
        azure_endpoint="https://my-resource.openai.azure.com",
        api_version="2024-02-01",
        session_id="my-session",
    )
    resp = await client.chat.completions.create(
        model="my-gpt4-deployment",
        messages=[{"role": "user", "content": "Hello"}],
    )
    print(resp.choices[0].message.content)

asyncio.run(main())

Cost basis

Events are journaled with provider="azure_openai". Token counts come from response.usage exactly as in the OpenAI SDK. Cost is computed against the canonical model family — TokenID maps your deployment back to the underlying model via the Azure Cost Management meter name during reconciliation, so dashboard rates match your invoice.

Parameters

Parameter Type Required Description
azure_endpoint string Yes Your Azure OpenAI resource endpoint, e.g. https://my-resource.openai.azure.com.
api_version string Yes Azure OpenAI API version, e.g. 2024-02-01.
azure_deployment string No Default deployment name, used when model is omitted on the call.
api_key string No Azure API key. Falls back to AZURE_OPENAI_API_KEY.
session_id string No Groups calls into a named session in your dashboard.
enforcement_config dict No Local enforcement rules (see Enforcement).