Overview
ChatGroq provides integration with Groq’s lightning-fast inference platform, supporting models like Llama, Qwen, GPT-OSS, and Kimi K2.Basic Usage
Configuration
Required Parameters
str
required
Groq model to use. Verified options:
meta-llama/llama-4-maverick-17b-128e-instruct: Latest Llama 4 with 128 expertsmeta-llama/llama-4-scout-17b-16e-instruct: Llama 4 Scout variantqwen/qwen3-32b: Qwen 3 32B modelmoonshotai/kimi-k2-instruct: Kimi K2 instruction modelopenai/gpt-oss-20b: GPT-OSS 20Bopenai/gpt-oss-120b: GPT-OSS 120B
Model Parameters
float
default:"None"
Sampling temperature (0.0 to 2.0). Controls randomness in responses.
str
default:"None"
Service tier for request routing:
auto, on_demand, or flex.float
default:"None"
Nucleus sampling parameter (0.0 to 1.0).
int
default:"None"
Random seed for deterministic output.
Client Parameters
str
default:"None"
Groq API key. Required for authentication.
Get your free API key at console.groq.com
str
default:"None"
Custom base URL for Groq API or compatible endpoints.
float
default:"None"
Request timeout in seconds or httpx.Timeout object.
int
default:"10"
Maximum number of retries for failed requests. Increased default for automation reliability.
Advanced Usage
Structured Output with JSON Schema
Groq supports structured output through JSON schema (for compatible models) or tool calling:JSON schema mode is supported by:
llama-4-maverick, llama-4-scout, gpt-oss-20b, and gpt-oss-120b. Tool calling mode is used for kimi-k2-instruct.Custom Base URL
Service Tiers
Environment Setup
.env
Error Handling
Properties
provider
Returns the provider name:"groq"
name
Returns the model name.Methods
get_client()
Returns anAsyncGroq client instance.
ainvoke()
Asynchronously invoke the model with messages.Parameters
- messages (
list[BaseMessage]): List of messages - output_format (
type[T] | None): Optional Pydantic model for structured output
Returns
ChatInvokeCompletion[T] | ChatInvokeCompletion[str] with:
completion: Response content (string or structured output)usage: Token usage including:prompt_tokens: Input tokenscompletion_tokens: Output tokenstotal_tokens: Total tokens used
stop_reason: Not available from Groq API
Groq doesn’t support cached tokens -
prompt_cached_tokens is always None.Model Capabilities
JSON Schema Models
These models support native JSON schema for structured output:meta-llama/llama-4-maverick-17b-128e-instructmeta-llama/llama-4-scout-17b-16e-instructopenai/gpt-oss-20bopenai/gpt-oss-120b
Tool Calling Models
These models use tool calling for structured output:moonshotai/kimi-k2-instruct
General Purpose
All models support regular text completion for general tasks.Performance
Groq is known for extremely fast inference speeds:- Lightning-fast token generation
- High throughput for production workloads
- Excellent for real-time applications
- Generous free tier for testing
Related
- ChatBrowserUse - Recommended provider
- ChatOpenAI
- ChatAnthropic