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

# Groq

> Trace Groq inference calls in TypeScript and Python — optimized for high-throughput, low-latency workloads — with wrapGroq() or patch_groq().

<Note>
  Available for: **Python** and **TypeScript**.
</Note>

Wrap your `Groq` client with `wrapGroq()` (TypeScript) to trace every inference call, including latency breakdowns useful for Groq's fast inference speeds — or patch the `groq` module with `patch_groq()` (Python).

## Installation

<CodeGroup>
  ```bash TypeScript theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  npm install @zespan/sdk groq-sdk
  ```

  ```bash Python theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  pip install zespan groq
  ```
</CodeGroup>

## Setup

<CodeGroup>
  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  import Groq from "groq-sdk";
  import { zespan } from "@zespan/sdk";

  zespan.init({ apiKey: process.env.ZESPAN_API_KEY! });

  const groq = zespan.wrapGroq(new Groq({ apiKey: process.env.GROQ_API_KEY! }));
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  import os
  import zespan

  zespan.init(api_key=os.environ["ZESPAN_API_KEY"])
  zespan.patch_groq()

  from groq import Groq  # import after patching
  client = Groq(api_key=os.environ["GROQ_API_KEY"])
  ```
</CodeGroup>

In TypeScript, `wrapGroq()` returns a wrapped client instance — pass it to any function that makes Groq calls. In Python, `patch_groq()` monkey-patches `groq.resources.chat.completions.Completions.create` in place, so `Groq()` (constructed after patching) is traced automatically with no wrapping step.

## Example

<CodeGroup>
  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  const completion = await groq.chat.completions.create({
    model: "llama-3.3-70b-versatile",
    messages: [{ role: "user", content: "Summarize this in one sentence." }],
  });
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  completion = client.chat.completions.create(
      model="llama-3.3-70b-versatile",
      messages=[{"role": "user", "content": "Summarize this in one sentence."}],
  )
  ```
</CodeGroup>

Streaming calls (`stream=True` / `stream: true`) are traced in both languages, including time-to-first-token.

## What gets captured

| Field         | Details                                                               |
| ------------- | --------------------------------------------------------------------- |
| Model         | `llama-3.3-70b-versatile`, `mixtral-8x7b-32768`, `gemma2-9b-it`, etc. |
| Input tokens  | From `usage.prompt_tokens`                                            |
| Output tokens | From `usage.completion_tokens`                                        |
| Cost          | Calculated from token counts and Groq pricing                         |
| Latency       | Total request duration (Groq latency is typically under 1s)           |
| Finish reason | `stop`, `length`, `tool_calls`                                        |
| Tool calls    | Tool name and parsed arguments, both languages                        |
