AIR

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. Raises AuthenticationError immediately if empty.
  • model (required): for example "llama-3.3-70b-versatile", unless overridden per request by ChatRequest.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: QuotaExceededError if the error body's code (or type) is insufficient_quota, or the message mentions credit, quota, or billing; otherwise AuthenticationError.
  • HTTP 429: same quota-keyword check as above; QuotaExceededError if matched, otherwise RateLimitError.
  • 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.