> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getnetra.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Groq

> Trace Groq LPU inference with Netra auto-instrumentation. Monitor ultra-fast model calls, token usage, and latency in real time.

![Groq](https://mintcdn.com/netra/IXT7TOAHn4HQhvyF/images/integration-logos/llm-providers/groq.png?fit=max\&auto=format\&n=IXT7TOAHn4HQhvyF\&q=85\&s=a2c43de7dbe8f9d4a04e2e9d95419b15)

## Installation

Install both the Netra SDK and Groq SDK:

```bash Python theme={null}
pip install netra-sdk groq
```

```bash Typescript theme={null}
npm install netra-sdk groq-sdk
```

## Usage

Initialize the Netra SDK with Groq instrumentation enabled. The SDK automatically traces all Groq API calls once initialized.

Set your Netra endpoint and API key before you call `Netra.init()`. Without `NETRA_OTLP_ENDPOINT`, the SDK prints spans to the console instead of sending them to Netra, and your dashboard stays empty.

```bash US Region theme={null}
export NETRA_OTLP_ENDPOINT="https://api.getnetra.ai/telemetry"
export NETRA_API_KEY="your-api-key-here"
```

```bash EU Region theme={null}
export NETRA_OTLP_ENDPOINT="https://api.eu.getnetra.ai/telemetry"
export NETRA_API_KEY="your-api-key-here"
```

Set these wherever your app runs, including Docker containers and CI jobs.

```python Python theme={null}
from netra import Netra
from groq import Groq
import os

# Initialize Netra with Groq instrumentation
Netra.init(
    app_name="my-ai-app",
    headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}",
    trace_content=True
)

# Use Groq client as usual - all calls are automatically traced
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))

completion = client.chat.completions.create(
    model="llama-3.1-70b-versatile",
    messages=[
        {"role": "user", "content": "What is observability?"}
    ]
)

print(completion.choices[0].message.content)
```

```typescript Typescript theme={null}
import { Netra } from "netra-sdk";
import Groq from "groq-sdk";

async function main() {
  // Initialize Netra with Groq instrumentation (must await)
  await Netra.init({
    appName: "my-ai-app",
    headers: `x-api-key=${process.env.NETRA_API_KEY}`,
    traceContent: true
  });

  // Use Groq client as usual - all calls are automatically traced
  const groq = new Groq({
    apiKey: process.env.GROQ_API_KEY
  });

  const completion = await groq.chat.completions.create({
    model: "llama-3.1-70b-versatile",
    messages: [
      { role: "user", content: "What is observability?" }
    ]
  });

  console.log(completion.choices[0].message.content);
}

main();
```

### Streaming Responses

The SDK automatically handles streaming responses and captures the complete output:

```python Python theme={null}
stream = client.chat.completions.create(
    model="llama-3.1-70b-versatile",
    messages=[{"role": "user", "content": "Tell me a story"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")
```

```typescript Typescript theme={null}
const stream = await groq.chat.completions.create({
  model: "llama-3.1-70b-versatile",
  messages: [{ role: "user", content: "Tell me a story" }],
  stream: true
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || "");
}
```

### Multiple Model Support

Groq supports various open-source models, all automatically instrumented:

```python Python theme={null}
# Using Mixtral
mixtral_response = client.chat.completions.create(
    model="mixtral-8x7b-32768",
    messages=[{"role": "user", "content": "Explain AI"}]
)

# Using Gemma
gemma_response = client.chat.completions.create(
    model="gemma-7b-it",
    messages=[{"role": "user", "content": "Hello"}]
)
```

```typescript Typescript theme={null}
// Using Mixtral
const mixtralResponse = await groq.chat.completions.create({
  model: "mixtral-8x7b-32768",
  messages: [{ role: "user", content: "Explain AI" }]
});

// Using Gemma
const gemmaResponse = await groq.chat.completions.create({
  model: "gemma-7b-it",
  messages: [{ role: "user", content: "Hello" }]
});
```

### Selective Instrumentation

Control which integrations are enabled using the `instruments` or `blockInstruments` configuration:

```python Python theme={null}
from netra import Netra
from netra.instrumentation.instruments import InstrumentSet

# Only enable Groq instrumentation
Netra.init(
    headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}",
    instruments={InstrumentSet.GROQ}
)

# Or block specific instrumentations
Netra.init(
    headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}",
    block_instruments={InstrumentSet.HTTPX}
)
```

```typescript Typescript theme={null}
import { Netra, NetraInstruments } from "netra-sdk";

// Only enable Groq instrumentation
await Netra.init({
  headers: `x-api-key=${process.env.NETRA_API_KEY}`,
  instruments: new Set([NetraInstruments.GROQ])
});

// Or block specific instrumentations
await Netra.init({
  headers: `x-api-key=${process.env.NETRA_API_KEY}`,
  blockInstruments: new Set([NetraInstruments.HTTP])
});
```

## Next Steps

* [Quick Start Guide](https://docs.getnetra.ai/quick-start/python) - Complete setup and configuration
* [Auto Instrumentation](https://docs.getnetra.ai/tracing/auto-instrumentation) - Automatic tracing for supported libraries
* [Decorators](https://docs.getnetra.ai/tracing/decorators) - Add custom tracing with `@workflow`, `@agent`, and `@task` decorators
* [Session Tracking](https://docs.getnetra.ai/tracing/session) - Track user sessions and conversations
* [Groq Documentation](https://console.groq.com/docs/quickstart) - Official Groq API quickstart guide


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.