Groq
To use GroqModel, you need to either install pydantic-ai, or install pydantic-ai-slim with the groq optional group:
pip install "pydantic-ai-slim[groq]"
uv add "pydantic-ai-slim[groq]"
To use Groq through their API, go to console.groq.com/keys and follow your nose until you find the place to generate an API key.
GroqModelName lists the latest Groq models for autocomplete. Any other model id the API accepts works too.
Once you have the API key, you can set it as an environment variable:
export GROQ_API_KEY='your-api-key'
You can then use GroqModel by name:
from pydantic_ai import Agent
agent = Agent('groq:llama-3.3-70b-versatile')
...
Or initialise the model directly with just the model name:
from pydantic_ai import Agent
from pydantic_ai.models.groq import GroqModel
model = GroqModel('llama-3.3-70b-versatile')
agent = Agent(model)
...
You can provide a custom Provider via the provider argument:
from pydantic_ai import Agent
from pydantic_ai.models.groq import GroqModel
from pydantic_ai.providers.groq import GroqProvider
model = GroqModel(
'llama-3.3-70b-versatile', provider=GroqProvider(api_key='your-api-key')
)
agent = Agent(model)
...
You can also customize the GroqProvider with a custom httpx.AsyncClient:
from httpx import AsyncClient
from pydantic_ai import Agent
from pydantic_ai.models.groq import GroqModel
from pydantic_ai.providers.groq import GroqProvider
custom_http_client = AsyncClient(timeout=30)
model = GroqModel(
'llama-3.3-70b-versatile',
provider=GroqProvider(api_key='your-api-key', http_client=custom_http_client),
)
agent = Agent(model)
...
NativeOutput sends Groq’s json_schema response format on the models below. Unless you pass strict to NativeOutput, the strict value Pydantic AI sends depends on the model:
| Models | strict sent |
|---|---|
openai/gpt-oss-*, qwen/qwen3.8-* | true when the schema meets strict mode’s requirements (for example, no field has a default), otherwise false |
qwen/qwen3.6-* | false |
meta-llama/llama-4-scout-17b-16e-instruct, meta-llama/llama-4-maverick-17b-128e-instruct | true |
moonshotai/*, meta-models/muse-spark-open | null; Groq documents best effort as the default |
Other Groq models raise a UserError for NativeOutput. PromptedOutput uses Groq’s JSON mode (json_object) on every model when the request has no function tools.
Groq can’t combine json_schema with function tools, so NativeOutput on an agent with function tools raises a UserError before the request is sent. Use the default ToolOutput instead.
Groq supports controlling the service tier to trade off throughput and reliability.
You can use the unified service_tier field or the provider-specific groq_service_tier field. groq_service_tier takes precedence over the unified field when both are set, and accepts Groq’s native values ('auto', 'on_demand', 'flex' or 'performance').
The unified field maps as follows for Groq:
'auto': passed through as'auto', so Groq picks the best tier available to you.'default': maps to'on_demand', Groq’s standard tier.'flex': passed through as'flex'. Flex requests fail fast with a 498 error when flex capacity is unavailable, which raises aModelUnavailableErrorthatModelFallbackandRetryOnModelErrorsact on.'priority': not part of Groq’s tier model and silently ignored.
Groq’s enterprise 'performance' tier is only reachable through groq_service_tier.
from pydantic_ai import Agent
from pydantic_ai.models.groq import GroqModelSettings
agent = Agent(
'groq:llama-3.3-70b-versatile',
model_settings=GroqModelSettings(service_tier='flex'),
)
...
The tier that served a non-streamed request is stored in ModelResponse.provider_details ['service_tier'].
A mid-conversation system prompt goes to Groq as a system message at its position in the conversation, except on openai/gpt-oss-*. There it goes as <system> text in a user turn, because Groq doesn’t keep a later system message in place on gpt-oss: a request that adds one reads the cached prefix only up to the instructions and tools, while the <system> text keeps the whole conversation before it cached.
The AsyncGroq client that the provider builds also retries failed requests on its own — max_retries=2 by default, like the OpenAI client it is modelled on. Pass groq_client=AsyncGroq(max_retries=0) to keep the retry policy in your transport alone, or set ModelSettings['max_retries'] to change the count without building the client. See Provider SDK retries for where this layer sits.