Groq
Import: from air.providers.groq import GroqProvider
Class name: GroqProvider
Provider name: "groq"
Constructor
python
GroqProvider(
api_key: str,
model: str,
base_url: str = "https://api.groq.com/openai/v1",
timeout: float = 60.0,
transport: httpx.AsyncBaseTransport | None = None,
)api_key(required): your Groq API key. RaisesAuthenticationErrorimmediately if empty.model(required): for example"llama-3.3-70b-versatile", unless overridden per request byChatRequest.model.base_url,timeout,transport: same meaning as the other providers.
Authentication
No environment variable is read automatically. Pass your key explicitly, for example os.environ["GROQ_API_KEY"].
Minimal setup
python
import os
from air import AIR
from air.providers.groq import GroqProvider
air = AIR()
air.add_provider(GroqProvider(api_key=os.environ["GROQ_API_KEY"], model="llama-3.3-70b-versatile"))
response = await air.chat("Hello")Request format
Sends a POST to {base_url}/chat/completions with an OpenAI compatible body: {"model": ..., "messages": [{"role": ..., "content": ...}, ...]}, plus temperature and max_tokens if set.
Response parsing
Reads choices[0].message.content for the reply, model for the model actually used, and usage.prompt_tokens / usage.completion_tokens / usage.total_tokens if present.
Error behavior
- HTTP 401 or 403:
QuotaExceededErrorif the error body'scode(ortype) isinsufficient_quota, or the message mentions credit, quota, or billing; otherwiseAuthenticationError. - HTTP 429: same quota-keyword check as above;
QuotaExceededErrorif matched, otherwiseRateLimitError. - Any other HTTP 400+:
ProviderAPIError. - Network timeout:
ProviderTimeoutError. - Other network/connection errors:
ProviderAPIError. - Non-JSON or unexpected response shape:
ProviderResponseError.
Limitations
Groq does not expose a remaining-quota endpoint. Capacity tracking only reflects usage Groq reports on each response.