Production ReadySDK • Go • v0.3.0

Groq SDK for Go

Production-ready Go SDK for Groq's LPU inference engine. Build blazing fast AI applications with comprehensive support for chat completions, streaming, audio transcription, embeddings, and advanced features like Compound AI, Reasoning Models, and RAG workflows.

v0.3.0 Released - Python SDK 0.37.0 Parity! Production-ready stable release with 73.5%+ test coverage (238 tests), A- audit grade (91%), zero race conditions, and complete Python SDK v0.37.0 parity. New features: MCP Tool Discovery, JSON Schema Output, Enhanced Usage Stats, Audio Enhancements, Cache Statistics.

In Production: This SDK is actively used in production at Zaguán. Successfully tested with OpenWebUI integration and Qwen-Code with full function calling support, handling real-world AI workloads with proven reliability.

Quality Metrics (v0.3.0)

73.5%+ Test Coverage

238 comprehensive tests covering all major functionality. 100% coverage on all 6 resource packages.

A- Audit Grade

91% audit score with comprehensive code quality analysis. Production-ready quality standards.

Zero Race Conditions

Verified with Go's race detector. Safe for production concurrent workloads.

Python SDK Parity

Complete feature parity with Python SDK v0.37.0. All APIs and advanced features supported.

Features

Blazing Fast

Optimized for Groq's LPU inference engine. Experience single-digit millisecond latency for LLM responses.

Chat Completions

Full support for chat completions with popular open models like Llama 3, Mixtral, and Gemma.

Audio Transcription

Convert audio to text using Whisper models. Fast and accurate transcription and translation.

Compound AI

Multi-model orchestration with custom tool configuration. Web search, code interpreter, and Wolfram integration.

Documents & RAG

Provide documents as context with citation support. Build powerful RAG workflows with text or JSON documents.

Multimodal Documents

Support for complex content parts including text, images, and structured JSON documents. Full parity with Groq API v0.37.0.

Reasoning Models

Advanced reasoning with configurable effort levels and output formats. Support for hidden, raw, and parsed reasoning.

Embeddings & Files

Generate vector embeddings and manage file uploads. Complete support for Models, Files, and Batches APIs.

Streaming First

Native Server-Sent Events (SSE) support with easy-to-use iterators. Real-time streaming for better UX.

Type Safety

Strict typing with generic Optional[T] types for precise control. Distinguish zero-values from omitted fields.

Context-Aware

All methods accept context.Context for cancellation and timeouts. Proper resource cleanup guaranteed.

Robust Error Handling

Exponential backoff retries, rate limit handling, and safe error types. Production-grade reliability.

Web Search Integration

Fine-grained web search control with domain filtering and result customization. Enhance AI responses with real-time data.

Functional Options

Clean, extensible API design following Go best practices. Flexible configuration with option functions.

Secure Authentication

API key support with TLS. Environment variable integration for safe credential management.

Well Tested

238 comprehensive tests with 73.5%+ coverage. All core APIs are 100% tested for production reliability.

Complete Documentation

Comprehensive examples and API documentation. Clear usage patterns and best practices for all features.

Quick Start

Prerequisites

Installation

go get github.com/ZaguanLabs/[email protected]

Basic Usage

package main

import (
    "context"
    "fmt"
    "os"

    "github.com/ZaguanLabs/groq-go/groq"
    "github.com/ZaguanLabs/groq-go/groq/option"
    "github.com/ZaguanLabs/groq-go/groq/types"
)

func main() {
    client, err := groq.NewClient(
        groq.WithAPIKey(os.Getenv("GROQ_API_KEY")),
    )
    if err != nil {
        panic(err)
    }

    resp, err := client.Chat.Create(context.Background(), &types.CreateChatCompletionRequest{
        Model: "llama3-8b-8192",
        Messages: []types.ChatCompletionMessageParam{
            {
                Role: types.RoleUser,
                Content: "Explain quantum computing in one sentence.",
            },
        },
        Temperature: option.Ptr(option.Some(0.7)),
    })

    if err != nil {
        panic(err)
    }

    fmt.Println(resp.Choices[0].Message.Content)
}

Streaming Usage

package main

import (
    "context"
    "fmt"
    "os"

    "github.com/ZaguanLabs/groq-go/groq"
    "github.com/ZaguanLabs/groq-go/groq/option"
    "github.com/ZaguanLabs/groq-go/groq/types"
)

func main() {
    client, err := groq.NewClient(
        groq.WithAPIKey(os.Getenv("GROQ_API_KEY")),
    )
    if err != nil {
        panic(err)
    }

    stream, err := client.Chat.CreateStream(context.Background(), &types.CreateChatCompletionRequest{
        Model: "llama3-8b-8192",
        Messages: []types.ChatCompletionMessageParam{
            {
                Role: types.RoleUser,
                Content: "Tell me a story about AI",
            },
        },
        Stream: option.Ptr(option.Some(true)),
    })

    if err != nil {
        panic(err)
    }
    defer stream.Close()

    // Process streaming chunks
    for stream.Next() {
        chunk := stream.Current()
        if len(chunk.Choices) > 0 {
            fmt.Print(chunk.Choices[0].Delta.Content)
        }
    }

    if err := stream.Err(); err != nil {
        panic(err)
    }
}

Environment Setup

Set your Groq API key as an environment variable:

export GROQ_API_KEY=your-api-key-here

Project Structure

groq-go/
├── groq/
│   ├── client.go          # Main client implementation
│   ├── chat.go            # Chat completions API
│   ├── audio.go           # Audio transcription API
│   ├── embeddings.go      # Embeddings API
│   ├── models.go          # Models API
│   ├── files.go           # Files API
│   ├── batches.go         # Batches API
│   ├── stream.go          # Streaming support
│   ├── types/
│   │   ├── chat.go        # Chat types
│   │   ├── audio.go       # Audio types
│   │   ├── embeddings.go  # Embeddings types
│   │   └── common.go      # Common types
│   └── option/
│       └── option.go      # Optional[T] types
├── examples/
│   ├── basic/             # Basic usage examples
│   ├── streaming/         # Streaming examples
│   ├── compound-ai/       # Compound AI examples
│   ├── reasoning/         # Reasoning models
│   └── rag/               # RAG workflows
├── go.mod
└── README.md

Roadmap

v0.1.0 - Initial Release

Core SDK functionality with chat completions, audio transcription, embeddings, and streaming support. Complete API coverage for all Groq endpoints.

v0.2.0 - Production Ready

Advanced features including Compound AI (multi-model orchestration with custom tools), Reasoning Models (configurable effort levels), Documents & Citations (RAG workflows), Web Search Integration, 135+ tests with 73.5% coverage, A- audit grade (91%), zero race conditions, and complete Python SDK v0.35.0 parity.

v0.2.1 - Multimodal Update

Added support for Multimodal Content Parts (Documents), synchronized with Python SDK v0.36.0, and expanded test coverage to 140+ tests.

v0.3.0 - Python SDK 0.37.0 Parity (Current)

Full API parity with official Groq Python SDK v0.37.0. New features: MCP Tool Discovery, JSON Schema Output, Enhanced Usage Stats (queue time, reasoning tokens, cached tokens), Audio Enhancements (sample rate control, URL-based transcription), Cache Statistics (DRAM/SRAM metrics). Expanded test suite to 238 tests.

Future Plans

Community feedback and improvements, additional API features as Groq releases them, performance optimizations, enhanced documentation and examples, continued Python SDK parity, bug fixes and stability improvements.

Development

Prerequisites

  • Go 1.21 or later
  • Groq API key

Building

# Clone the repository
git clone https://github.com/ZaguanLabs/groq-go.git
cd groq-go

# Build
go build ./...

# Run tests
go test ./...

# Run tests with coverage
go test -cover ./...

# Run race detector
go test -race ./...

Running Examples

# Set your API key
export GROQ_API_KEY=your-api-key-here

# Run basic example
go run examples/basic/main.go

# Run streaming example
go run examples/streaming/main.go

# Run compound AI example
go run examples/compound-ai/main.go

# Run reasoning example
go run examples/reasoning/main.go

Contributing

Contributions are welcome! Whether it's bug reports, feature requests, or pull requests, we appreciate all forms of contribution.

Apache 2.0 Licensed - The Groq SDK for Go is free and open source software. You're welcome to use, modify, and distribute it for any purpose.

Ready to Build with Groq?

Check out the repository for full documentation, examples, and API reference.