simple-groq-rs

Crates.iosimple-groq-rs
lib.rssimple-groq-rs
version0.1.3
created_at2025-12-30 15:13:39.201272+00
updated_at2025-12-30 15:53:06.90437+00
descriptionA simple, async Rust client for the Groq API (OpenAPI-compatible)
homepage
repositoryhttps://github.com/olatunbosunoyeleke94/simple-groq-rs
max_upload_size
id2012807
size50,457
Olatunbosun Oyeleke (olatunbosunoyeleke94)

documentation

README

simple-groq-rs

A minimal, ergonomic, async Rust client for the Groq inference API.

Groq provides lightning-fast inference for open-source models (Llama 3.1, Mixtral, Gemma, etc.) and is fully compatible with the OpenAI API format. This crate gives you a clean, lightweight way to call Groq from Rust with almost zero overhead.

Features

  • Simple, idiomatic API
  • Async (powered by reqwest)
  • No heavy dependencies
  • Easy environment variable setup
  • Ready for streaming, vision, and tools (future extensions)

Installation

Add this to your Cargo.toml:

[dependencies]
simple-groq-rs = "0.1.0"

Quick Start:

  • Get a free API key at console.groq.com/keys (no credit card required).
  • Set the key in your environment:
export GROQ_API_KEY="gsk_your_key_here"

Code Exmaple:

use simple_groq_rs::{GroqClient, Message};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = GroqClient::from_env()?; // Loads GROQ_API_KEY automatically

    let messages = vec![
        Message::system("You are a helpful and concise assistant."),
        Message::user("Explain Rust's borrow checker in one short paragraph."),
    ];

    let response = client
        .chat_completion("llama-3.1-70b-versatile", messages, None, None)
        .await?;

    println!("Groq response:\n{}", response);
    Ok(())
}

Popular free-tier models (as of Dec 2025):

  • llama-3.1-8b-instant – fastest, great for quick tasks
  • llama-3.1-70b-versatile – highest quality
  • mixtral-8x7b-32768
  • gemma2-9b-it

Running Examples:

This crate includes ready-to-run examples:


# Set your key (once per terminal session)
export GROQ_API_KEY="gsk_your_key_here"

# Simple chat example
cargo run --example simple

# List all models available to your account
cargo run --example list_models

Commit count: 0

cargo fmt