Groq
Trace Groq model calls with cetra from Python, through the Groq SDK or the OpenAI client.
Install
Section titled “Install”pip install "cetra-sdk[groq]" groqSet up
Section titled “Set up”import os
import cetrafrom groq import Groq
cetra.init(instrument=["groq"])
client = Groq(api_key=os.environ["GROQ_API_KEY"])response = client.chat.completions.create( model="openai/gpt-oss-20b", messages=[{"role": "user", "content": "What is the capital of France?"}],)print(response.choices[0].message.content)
cetra.flush()Through the OpenAI client
Section titled “Through the OpenAI client”Groq also serves an OpenAI-compatible endpoint. The provider comes from the endpoint host.
import os
import cetrafrom openai import OpenAI
cetra.init(instrument=["openai"])
client = OpenAI(base_url="https://api.groq.com/openai/v1", api_key=os.environ["GROQ_API_KEY"])response = client.chat.completions.create( model="openai/gpt-oss-20b", messages=[{"role": "user", "content": "What is the capital of France?"}],)print(response.choices[0].message.content)
cetra.flush()What you get
Section titled “What you get”- Each chat completion is an
llmspan with the providergroq. - Input and output token counts come from the response.
- Cost comes from the built-in prices.
- Through the OpenAI client, the endpoint host is in
server.address, and cetra names the provider from it.
Limits
Section titled “Limits”- The fixtures were captured with groq 1.7.0 and openinference-instrumentation-groq 0.1.40.
- 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.