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
go get github.com/langwatch/langwatch/sdk-go github.com/openai/openai-go
Usage
The LangWatch API key is configured by default via the LANGWATCH_API_KEY environment variable.
Set your Groq API key as an environment variable:
export GROQ_API_KEY="your-groq-api-key"
Configure the OpenAI client to point at Groq’s endpoint and enable the LangWatch middleware:
package main
import (
"context"
"log"
"os"
otelopenai "github.com/langwatch/langwatch/sdk-go/instrumentation/openai"
"github.com/openai/openai-go"
oaioption "github.com/openai/openai-go/option"
)
func main() {
ctx := context.Background()
client := openai.NewClient(
oaioption.WithBaseURL("https://api.groq.com/openai/v1"),
oaioption.WithAPIKey(os.Getenv("GROQ_API_KEY")),
oaioption.WithMiddleware(otelopenai.Middleware("<project_name>",
otelopenai.WithCaptureInput(),
otelopenai.WithCaptureOutput(),
)),
)
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! Can you explain the concept of inference speed?"),
},
})
if err != nil {
log.Fatalf("Groq API call failed: %v", err)
}
log.Printf("Groq response: %s", response.Choices[0].Message.Content)
}
Observability Metrics
The middleware automatically captures:
- Prompt and completion text (configurable)
- Token usage (prompt, completion, total)
- Full request/response metadata
- Latency and error details