Trace Groq chat completions

Use traceAI-groq to send Groq chat completion spans to an Observe project in Future AGI.

Trace Groq chat completions in Future AGI.

Use Python 3.10–3.13, as required by the traceAI-groq package.

1. Install

Install the instrumentation package.

pip install traceAI-groq

2. Set credentials

Set your Future AGI and Groq credentials in the process running the example.

import os

os.environ["FI_API_KEY"] = "your-futureagi-api-key"
os.environ["FI_SECRET_KEY"] = "your-futureagi-secret-key"
os.environ["GROQ_API_KEY"] = "your-groq-api-key"

3. Register tracing

Choose the Observe project name that will receive these spans.

from fi_instrumentation import register
from fi_instrumentation.fi_types import ProjectType

trace_provider = register(
    project_type=ProjectType.OBSERVE,
    project_name="groq_project",
)

4. Instrument the client

Attach the Groq instrumentor to your trace provider before making a model call.

from traceai_groq import GroqInstrumentor

GroqInstrumentor().instrument(tracer_provider=trace_provider)

5. Run a chat completion

Run a chat completion with your instrumented client.

from groq import Groq

client = Groq()

chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "system",
            "content": "you are a helpful assistant."
        },
        {
            "role": "user",
            "content": "Explain the importance of fast language models",
        }
    ],
    model="llama-3.3-70b-versatile",
)

print(chat_completion.choices[0].message.content)

Open the groq_project project in Future AGI to inspect the recorded call.

Was this page helpful?

Questions & Discussion