Azure OpenAI
Trace Azure OpenAI model calls with cetra through the OpenAI SDK’s Azure client.
Install
Section titled “Install”pip install "cetra-sdk[openai]" openainpm install @cetra-ai/sdk @arizeai/openinference-instrumentation-openai openaiSet up
Section titled “Set up”import os
import cetrafrom 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()import { init } from "@cetra-ai/sdk";import { openai } from "@cetra-ai/sdk/openai";import OpenAI, { AzureOpenAI } from "openai";init({ apiKey: process.env.CETRA_API_KEY, instrument: [openai(OpenAI)] });const client = new AzureOpenAI({ endpoint: process.env.AZURE_OPENAI_ENDPOINT, apiKey: process.env.AZURE_OPENAI_API_KEY, apiVersion: "2024-10-21",});await client.chat.completions.create({ model: "<DEPLOYMENT_NAME>", messages: [{ role: "user", content: "What is the capital of France?" }],});What you get
Section titled “What you get”- Each chat completion is an
llmspan with the providerazure.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.
Limits
Section titled “Limits”- 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.
- Traces: read the trace as a tree and a timeline.
- Cost and tokens: how cost is computed from the token counts.
- Custom model prices: price a model the built-in prices do not cover.