Skip to content

Get a free Groq or Gemini API key and run your first Python request.

Create a key in the provider’s console and call a text model from your own Python environment. The script sends your key directly to the provider.

quickstart.pyPython
import os
from openai import APIStatusError, OpenAI

client = OpenAI(
    api_key=os.environ["GROQ_API_KEY"],
    base_url="https://api.groq.com/openai/v1",
    max_retries=0,
    timeout=30,
)
openai/gpt-oss-20bOpenAI SDK

Choose a provider

Compare the documented free tiers and pick an endpoint for your first request.

Groq

openai/gpt-oss-20b

Published free plan: 30 requests per minute, 1000 per day, and 8000 tokens per minute. Limits are shared within your organization.

Free-account call pending verification

Gemini

gemini-3.5-flash-lite

Text input and output are listed as free on the free tier. Limits vary by project and model. Daily request quotas reset at midnight Pacific time.

Free-account call pending verification

Official documentation checked 2026-12-02.

Download catalog (JSON)

Run your first request with Groq

You’ll need Python 3 and a key from the selected provider. Run both commands in the same terminal session.

Install the SDK and set your key

PowerShell
py -m venv .venv
.\.venv\Scripts\python.exe -m pip install openai
$secret = Read-Host 'Paste your Groq key' -AsSecureString
$env:GROQ_API_KEY = [System.Net.NetworkCredential]::new('', $secret).Password
Remove-Variable secret

Save this as quickstart.py

quickstart.py
import os
from openai import APIStatusError, OpenAI

client = OpenAI(
    api_key=os.environ["GROQ_API_KEY"],
    base_url="https://api.groq.com/openai/v1",
    max_retries=0,
    timeout=30,
)

try:
    reply = client.chat.completions.create(
        model="openai/gpt-oss-20b",
        messages=[{"role": "user", "content": "Reply with OK."}],
    )
    print(reply.choices[0].message.content)
except APIStatusError as error:
    raise SystemExit(f"HTTP {error.status_code}: {error.message}") from None

Run the script

Terminal
.\.venv\Scripts\python.exe quickstart.py

A successful request prints the model’s reply. If it fails with an HTTP status, use the guide below.

Fix common API errors

401

Check your API key

Make sure you set the selected provider’s key in this terminal. If it was revoked or copied incorrectly, create a new one in the official console.

403

Check account access

Read the provider’s error for the account, region, or model restriction. Check that the selected project can call this model.

429

Check the rate limit

Read the provider’s error and honor Retry-After when it is present. If the free quota is exhausted, wait for the next reset or switch to a provider where you still have quota.

Switch to Gemini

Common questions

How does the free tier work?

The provider sets which models qualify, what your account can use, and when your quota resets. Check the official limits for your account before running the snippet.

Do I need a credit card?

Billing requirements depend on the provider, plan, and account. Check your Groq plan or AI Studio project in the official console before enabling billing.

Where does my API key go?

Your key stays in your terminal environment. The Python script reads it and sends it directly to the selected provider when you run it.

Can I use the same Base URL for both providers?

Groq and Gemini each have their own OpenAI-compatible Base URL. Selecting a provider updates the URL, model name, and environment variable in the snippet.