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

# Groq Integration

> Instrument Groq API calls in Go using LangWatch for fast LLM observability, cost tracking, and agent evaluation insights.

LangWatch can trace calls to the Groq API, allowing you to monitor its high-speed inference capabilities. Groq provides an OpenAI-compatible endpoint, so you can reuse the `otelopenai` middleware with minimal changes.

## Installation

```bash  theme={null}
go get github.com/langwatch/langwatch/sdk-go github.com/openai/openai-go
```

## Usage

<Info>
  Set `LANGWATCH_API_KEY` and `GROQ_API_KEY` environment variables before running.
</Info>

```go  theme={null}
package main

import (
	"context"
	"log"
	"os"

	langwatch "github.com/langwatch/langwatch/sdk-go"
	otelopenai "github.com/langwatch/langwatch/sdk-go/instrumentation/openai"
	"github.com/openai/openai-go"
	oaioption "github.com/openai/openai-go/option"
	"go.opentelemetry.io/otel"
	sdktrace "go.opentelemetry.io/otel/sdk/trace"
)

func main() {
	ctx := context.Background()

	// Set up LangWatch exporter
	exporter, err := langwatch.NewDefaultExporter(ctx)
	if err != nil {
		log.Fatalf("failed to create exporter: %v", err)
	}
	tp := sdktrace.NewTracerProvider(sdktrace.WithBatcher(exporter))
	otel.SetTracerProvider(tp)
	defer tp.Shutdown(ctx) // Critical: ensures traces are flushed

	// Create Groq client via OpenAI-compatible API
	client := openai.NewClient(
		oaioption.WithBaseURL("https://api.groq.com/openai/v1"),
		oaioption.WithAPIKey(os.Getenv("GROQ_API_KEY")),
		oaioption.WithMiddleware(otelopenai.Middleware("my-app",
			otelopenai.WithCaptureInput(),
			otelopenai.WithCaptureOutput(),
			otelopenai.WithGenAISystem("groq"),
		)),
	)

	response, err := client.Chat.Completions.New(ctx, openai.ChatCompletionNewParams{
		Model: "openai/gpt-oss-20b",
		Messages: []openai.ChatCompletionMessageParamUnion{
			openai.SystemMessage("You are a helpful assistant."),
			openai.UserMessage("Hello, Groq!"),
		},
	})
	if err != nil {
		log.Fatalf("Groq API call failed: %v", err)
	}

	log.Printf("Response: %s", response.Choices[0].Message.Content)
}
```

<Warning>
  The `defer tp.Shutdown(ctx)` call is essential. Without it, traces buffered in memory will be lost when your application exits.
</Warning>

## Related

* [Capturing RAG](/integration/python/tutorials/capturing-rag)
* [Capturing Metadata and Attributes](/integration/python/tutorials/capturing-metadata)
* [Capturing Evaluations & Guardrails](/integration/python/tutorials/capturing-evaluations-guardrails)
