ai-stack is designed to work entirely locally with no cloud dependency. But free-tier access to frontier cloud models (Claude and Gemini) is available as an optional augment — useful when a task genuinely needs more capability than a 14B local model provides.
This is handled through LiteLLM, which proxies cloud API calls through a local endpoint. From OpenCode's perspective, it's just another provider.
Both Anthropic (Claude) and Google (Gemini) offer free API access:
- Claude (via Anthropic): Generous free tier on Claude Haiku and Claude Sonnet. Rate-limited, but sufficient for occasional use. Requires account creation at console.anthropic.com.
- Gemini (via Google AI Studio): Free tier on Gemini Flash and Gemini Pro. More liberal rate limits. Requires Google account at aistudio.google.com.
Free tiers can be revoked or changed by the providers. Check current limits at their respective developer consoles.
- Go to console.anthropic.com
- Create an account (free)
- Go to API Keys → Create Key
- Copy the key (starts with
sk-ant-...)
- Go to aistudio.google.com
- Sign in with your Google account
- Click Get API Key → Create API key in new project
- Copy the key
Edit .env and set:
ANTHROPIC_API_KEY=sk-ant-your-key-here
GEMINI_API_KEY=your-gemini-key-hereThen restart:
sudo systemctl restart ai-stack.serviceIf you configured Bitwarden during install, use the placeholder format instead:
ANTHROPIC_API_KEY=<vaultwarden:your-org-id/anthropic-api-key>
GEMINI_API_KEY=<vaultwarden:your-org-id/gemini-api-key>The stack resolves these at startup. See docs/secret-management.md for details.
After adding keys and restarting:
# Check LiteLLM is healthy
curl http://localhost:4000/health/liveness
# List available models
curl http://localhost:4000/v1/models -H "Authorization: Bearer $LITELLM_MASTER_KEY" | python3 -m json.toolYou should see Claude and Gemini models in the list.
Cloud models are available through the LiteLLM provider (:4000). In OpenCode, you can switch providers or configure cloud models as a fallback.
To direct a specific request to a cloud model, select the LiteLLM provider in OpenCode and choose the model explicitly. The smart router routes to local models by default — cloud models are not part of the automatic routing unless you configure them in the router's MODELS map.
When to use cloud models:
- Complex reasoning that requires a frontier-scale model
- Very long documents that exceed local model context limits
- Tasks where output quality matters more than privacy/cost
When to stick with local:
- Anything involving sensitive information
- Repetitive or bulk tasks (free tier has rate limits)
- When you need fast iteration (local is often faster for short tasks)
Cloud model definitions live in proxy/litellm_config.yaml. The default config includes:
model_list:
- model_name: claude-haiku
litellm_params:
model: anthropic/claude-haiku-20240307
api_key: os.environ/ANTHROPIC_API_KEY
- model_name: claude-sonnet
litellm_params:
model: anthropic/claude-sonnet-20240620
api_key: os.environ/ANTHROPIC_API_KEY
- model_name: gemini-flash
litellm_params:
model: gemini/gemini-1.5-flash
api_key: os.environ/GEMINI_API_KEY
- model_name: gemini-pro
litellm_params:
model: gemini/gemini-1.5-pro
api_key: os.environ/GEMINI_API_KEYTo add more models or change which models are available, edit this file and restart the stack.
Free tiers have limits. If you hit them, LiteLLM will return a rate limit error (429). The stack does not automatically retry or fall back to another provider.
To avoid surprises:
- Use local models for routine tasks
- Reserve cloud calls for tasks where the quality difference matters
- Watch your usage at the provider consoles
If you start regularly hitting free tier limits and want to add paid credits, simply add credits to your Anthropic or Google AI account — no config changes needed.