Groq Ruby logo

Groq Ruby

Free

Groq Cloud runs LLM models fast and cheap. This is a convenience client library for Ruby. ![GitHub Repo stars](https://img.shields.io/github/stars/drnic/groq-ruby?style=social)

FreeFree tier
Inputs: textOutputs: text
Type
Open Source

About Groq Ruby

Groq Cloud runs LLM models fast and cheap, including Llama 3.1, Mixtral, Gemma, and more at hundreds of tokens per second and cents per million tokens. This convenience client library for Ruby (a RubyGem) provides a simple interface to interact with the Groq Cloud API, which follows a subset of the OpenAI API schema. The gem offers helper methods for chat roles (User, Assistant, System), JSON mode for structured outputs, and a Rails generator for configuration. Installation is via 'bundle add groq' or 'gem install groq'. Usage requires an API key from console.groq.com, set via the GROQ_API_KEY environment variable or explicit configuration.

Key Features

Convenient RubyGem wrapper for Groq Cloud API
Helper methods for User, Assistant, and System chat roles
JSON mode for structured model responses
Rails generator for initializer configuration
Simple chat function for single or multi-turn conversations
Supports multiple models (Llama 3.1, Mixtral, Gemma, etc.)

Pros & Cons

Pros
  • Extremely fast inference (hundreds of tokens per second) and low cost (cents per million tokens)
  • Simple Ruby API with helpful abstractions for chat roles
  • Easy installation and configuration, including Rails support
  • JSON mode enables predictable structured outputs
  • Open-source and free to use (no additional cost beyond Groq Cloud API usage)
Cons
  • Requires a Groq Cloud API key and internet connection
  • Limited to models offered by Groq Cloud (not a general-purpose LLM client)
  • Relatively new project (49 commits, small community) — may have limited documentation or support
  • Only supports the subset of OpenAI API that Groq implements; not all OpenAI features available

Best For

Building Ruby applications with fast, low-cost LLM inferenceIntegrating Groq Cloud into Ruby on Rails applicationsPrototyping chat-based AI features with minimal boilerplateLeveraging JSON mode for structured data extraction from LLMs

FAQ

How do I install the groq-ruby gem?
Add 'groq' to your Gemfile with `bundle add groq`, or install it directly with `gem install groq`.
How do I configure my API key?
Set the environment variable GROQ_API_KEY, or pass it explicitly when creating a client: `Groq::Client.new(api_key: '...')`. You can also generate a Rails initializer with `rails g groq:install`.
What models are supported?
The gem supports any model available on Groq Cloud, including Llama 3.1, Mixtral, Gemma, and others. The default model is 'llama-3.1-8b-instant'.
How do I use JSON mode?
Pass `json: true` to the chat method. The model will respond with JSON, which can be parsed with `JSON.parse(response['content'])`.