For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
DiscordPlatform
DocumentationIntegrationsAPI referenceSDKsChangelog
DocumentationIntegrationsAPI referenceSDKsChangelog
    • Overview
  • Tracing
      • OpenAI SDK
      • Instructor
      • Anthropic SDK
      • Google GenAI
      • LiteLLM
      • RubyLLM
      • Vertex AI
      • AWS Bedrock
      • Cohere
      • Groq
      • Mistral AI
      • Ollama
      • Portkey
      • Watsonx
      • Together AI
      • Aleph Alpha
      • HuggingFace
      • Replicate
      • SageMaker
      • Respan API
  • Gateway
  • Others
  • Migrating
    • Braintrust
    • Langfuse
    • Portkey
LogoLogo
DiscordPlatform
On this page
  • Setup
  • Configuration
  • Attributes
  • Examples
  • Streaming
  • Tool calling
TracingLLM SDKs

Groq (tracing)

Was this page helpful?
Previous

Mistral AI (tracing)

Next
Built with

The Groq Python SDK is the official client for Groq’s inference API. respan-instrumentation-groq activates the Groq OpenInference wrapper and normalizes emitted spans to the Respan tracing pipeline.

Set up Respan
  1. Sign up - Create an account at platform.respan.ai
  2. Create an API key - Generate one on the API keys page
Use Respan Gateway

See Groq gateway setup to route Groq model calls through the Respan gateway.

Example projects
  • Respan example projects

Setup

1

Install packages

$pip install respan-ai respan-instrumentation-groq groq python-dotenv
2

Set environment variables

$export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
$export GROQ_API_KEY="YOUR_GROQ_API_KEY"

Optional:

$export RESPAN_BASE_URL="https://api.respan.ai/api"
$export GROQ_MODEL="llama-3.1-8b-instant"
3

Initialize and run

1import os
2
3from dotenv import load_dotenv
4from groq import Groq
5from respan import Respan, workflow
6from respan_instrumentation_groq import GroqInstrumentor
7
8load_dotenv()
9
10respan = Respan(
11 api_key=os.environ["RESPAN_API_KEY"],
12 base_url=os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/api"),
13 instrumentations=[GroqInstrumentor()],
14)
15client = Groq(api_key=os.environ["GROQ_API_KEY"])
16
17
18@workflow(name="groq_chat_completion")
19def run_chat() -> str:
20 response = client.chat.completions.create(
21 model=os.getenv("GROQ_MODEL", "llama-3.1-8b-instant"),
22 messages=[
23 {
24 "role": "user",
25 "content": "Reply with one concise sentence about tracing.",
26 }
27 ],
28 )
29 return response.choices[0].message.content or ""
30
31
32try:
33 print(run_chat())
34finally:
35 respan.flush()
36 respan.shutdown()
4

View your trace

Open the Traces page and search for the workflow name groq_chat_completion.

Configuration

ParameterTypeDefaultDescription
**instrumentor_kwargsdict{}Extra keyword arguments forwarded to the upstream Groq OpenInference instrumentor.

Attributes

Attach customer identifiers, thread IDs, workflow names, and metadata to Groq calls with propagate_attributes.

1from respan import propagate_attributes
2
3with propagate_attributes(
4 customer_identifier="user_123",
5 thread_identifier="conversation_456",
6 trace_group_identifier="groq_support_chat.workflow",
7 metadata={"plan": "pro", "workflow_name": "groq_support_chat.workflow"},
8):
9 response = client.chat.completions.create(
10 model="llama-3.1-8b-instant",
11 messages=[{"role": "user", "content": "Summarize our support policy."}],
12 )
AttributeTypeDescription
customer_identifierstrIdentifies the end user in Respan analytics.
thread_identifierstrGroups related messages into a conversation.
trace_group_identifierstrGroups spans by workflow name.
metadatadictCustom key-value pairs merged with default metadata.

Examples

Streaming

1stream = client.chat.completions.create(
2 model="llama-3.1-8b-instant",
3 messages=[{"role": "user", "content": "Write a short haiku about tracing."}],
4 stream=True,
5)
6
7for chunk in stream:
8 content = chunk.choices[0].delta.content
9 if content:
10 print(content, end="", flush=True)

Tool calling

1response = client.chat.completions.create(
2 model="llama-3.1-8b-instant",
3 messages=[{"role": "user", "content": "What is the weather in Boston?"}],
4 tools=[
5 {
6 "type": "function",
7 "function": {
8 "name": "get_weather",
9 "description": "Get the current weather for a city.",
10 "parameters": {
11 "type": "object",
12 "properties": {"city": {"type": "string"}},
13 "required": ["city"],
14 },
15 },
16 }
17 ],
18)
19print(response.choices[0].message.tool_calls)