GroqProvider connects Logicore to Groq Cloud, which runs models on Groq’s custom Language Processing Units (LPUs). Groq consistently delivers the lowest time-to-first-token of any cloud provider, making it the best choice for latency-sensitive and high-throughput use cases.
Installation
Set your API key
- Environment variable (recommended)
- Pass directly
Constructor parameters
The Groq model ID. Examples:
"llama-3.3-70b-versatile", "llama-3.1-8b-instant", "mixtral-8x7b-32768", "meta-llama/llama-4-scout-17b-16e-instruct" (vision). See the full list at console.groq.com/docs/models.Your Groq API key. If omitted, the provider reads
GROQ_API_KEY from the environment. Raises ValueError if neither is set.Basic usage
Streaming
GroqProvider streams using Groq’s sync streaming iterator, wrapped for async compatibility:
chat_stream reconstructs tool-call chunks from the stream and returns a ChatCompletionMessage object when streaming is complete.
Tool calling
tool_choice="auto" is set automatically.
Vision / multimodal
Select a Groq vision model (currentlymeta-llama/llama-4-scout-17b-16e-instruct) and pass image parts:
image_url values:
- Local file path — automatically converted to a
data:image/...;base64,...URL https://image URLdata:image/...;base64,...inline data
GroqProvider detects local image paths and base64-encodes them before sending to the API. No extra handling is needed on your side.Why Groq is fast
Groq’s LPU (Language Processing Unit) architecture is purpose-built for sequential token generation. Unlike GPU-based providers, LPUs avoid memory-bandwidth bottlenecks, enabling sustained throughput of hundreds of tokens per second with sub-50ms time-to-first-token. This makesGroqProvider the recommended choice when:
- User-facing latency is critical (chatbots, copilots)
- You need high throughput at low cost
- You want a cloud provider as a fast fallback to a local Ollama setup
Troubleshooting
ValueError: Groq API key is required
ValueError: Groq API key is required
The
api_key argument was not passed and GROQ_API_KEY is not set. Obtain a key at console.groq.com and export it.ValueError: Groq model returned empty response
ValueError: Groq model returned empty response
The model returned a response with neither content nor tool calls. This occasionally happens with certain instruction patterns. Try rephrasing or switching to
llama-3.3-70b-versatile, which has the best instruction-following of Groq’s available models.ValueError: Groq model does not support vision capabilities
ValueError: Groq model does not support vision capabilities
You passed an image to a text-only model. Switch to
meta-llama/llama-4-scout-17b-16e-instruct for vision tasks.RateLimitError: 429 Too Many Requests
RateLimitError: 429 Too Many Requests
Groq’s free tier enforces per-minute token limits. Add exponential back-off or upgrade to a paid plan. You can also set up a fallback to
OpenAIProvider for burst traffic.Model not found or invalid model name
Model not found or invalid model name
Groq changes available models periodically. Check the current list at console.groq.com/docs/models and update
model_name accordingly.