Skip to content
GitHubLog inStart free
cetra is not released yet. These docs describe the development version.

Azure OpenAI

Trace Azure OpenAI model calls with cetra through the OpenAI SDK’s Azure client.

Terminal window
pip install "cetra-sdk[openai]" openai
import os
import cetra
from openai import AzureOpenAI
cetra.init(instrument=["openai"])
client = AzureOpenAI(
azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
api_key=os.environ["AZURE_OPENAI_API_KEY"],
api_version="2024-10-21",
)
response = client.chat.completions.create(
model="<DEPLOYMENT_NAME>",
messages=[{"role": "user", "content": "What is the capital of France?"}],
)
print(response.choices[0].message.content)
cetra.flush()
  • Each chat completion is an llm span with the provider azure.ai.openai.
  • Input and output token counts come from the response.
  • Cost comes from the built-in prices.
  • The endpoint host is in server.address, and cetra names the provider from it.
  • The span shows the deployment’s base model, which prices it.
  • Calling Azure OpenAI needs an Azure subscription. The fixtures were captured against cetra’s mock.
  • The fixtures were captured with openai 3.45.0 and openinference-instrumentation-openai 0.1.69.
  • If a field is missing, look at the span’s Attributes tab and compare it with Span attributes.