Use Gab AI with OpenCode: setup, access and checks
Choose Gab models for your OpenCode projects, with separate setup instructions for v1 and v2.
Connect your client to Gab AI
Have your client installed and a Gab API key ready. Follow the configuration for your client below, then select a model and try a first prompt.
Prerequisites
- OpenCode installed on your computer.
- A Gab API key and the model ID you want to use.
Choose the provider format for your OpenCode version
Run opencode --version before editing. OpenCode v1 uses provider, npm and options; v2 uses providers, package and settings. Save the configuration globally or in your project, and use https://gab.ai/v1 as the base URL. The examples below select Responses.
- OpenCode v1: use npm: "@ai-sdk/openai" under provider.gab-ai, with options.baseURL.
- OpenCode v2: use package: "@opencode/ai/providers/openai/responses" under providers.gab-ai, with settings.baseURL.
Configure OpenCode v1
The Gab setup endpoint generates a v1 provider configuration. Save it separately and merge its Gab provider into your existing file. Use its model IDs and capabilities when updating the example. Keep a concrete model ID for auxiliary calls.
curl -fsSL "https://gab.ai/v1/agent-setup?client=opencode" | jq .config > gab-opencode-v1.json{
"$schema": "https://opencode.ai/config.json",
"model": "gab-ai/claude-sonnet-4-5",
"provider": {
"gab-ai": {
"npm": "@ai-sdk/openai",
"name": "Gab AI",
"options": {
"baseURL": "https://gab.ai/v1"
},
"models": {
"claude-sonnet-4-5": {
"name": "Claude Sonnet 4.5",
"limit": {
"context": 200000,
"output": 64000
},
"modalities": {
"input": [
"text",
"image"
],
"output": [
"text"
]
},
"tool_call": true
}
}
}
}
}Connect your API key and select a model
- Save or merge the v1 configuration, then start OpenCode in your project.
- Run /connect, select Gab AI and paste your Gab AI API key.
- Run /models and select a Gab AI model.
Configure OpenCode v2
Use the providers map with package and settings. The example selects the OpenAI Responses adapter with Gab’s base URL. For environment-based authentication, replace YOUR_GAB_API_KEY with your complete Gab key and run the export command in the shell that launches OpenCode. Alternatively, connect the named Gab provider through /connect. Choose the model in /models.
export GAB_API_KEY="YOUR_GAB_API_KEY"{
"$schema": "https://opencode.ai/config.json",
"model": "gab-ai/claude-sonnet-4-5",
"providers": {
"gab-ai": {
"name": "Gab AI",
"env": [
"GAB_API_KEY"
],
"package": "@opencode/ai/providers/openai/responses",
"settings": {
"baseURL": "https://gab.ai/v1"
},
"models": {
"claude-sonnet-4-5": {
"name": "Claude Sonnet 4.5",
"limit": {
"context": 200000,
"output": 64000
},
"capabilities": {
"tools": true,
"input": [
"text",
"image"
],
"output": [
"text"
]
}
}
}
}
}
}Choose models for your coding tasks
Use model IDs from /v1/models. Match the configured context/output limits and tool/image capabilities to the catalog. For agent work, choose a model that supports function calling. V1 uses tool_call and modalities; v2 uses capabilities.
curl -fsSL https://gab.ai/v1/models | jq -r ' .data[] | select(.capabilities.function_calling == true) | select(any(.recommended_for[]?; . == "coding")) | .id'Choose capabilities for your workflow
Match the Gab model’s capabilities to the inputs and tools your client sends.
- Responses or Chat Completions, selected by the provider adapter.
- Streaming and function calling with models that advertise those capabilities.
- Image inputs when both the selected model and client support the requested format.
Troubleshooting
- 401 authentication_error: re-connect your Gab AI key, or check that GAB_API_KEY is available to the v2 OpenCode server.
- 400 invalid_model: check the model ID or alias against /v1/models. In v2, modelID can map a custom OpenCode model key to the ID sent to Gab AI.
- Provider settings ignored or models missing: check your OpenCode version. v1 uses provider/npm/options; v2 uses providers/package/settings.
- Cannot find package '@opencode/ai' with @opencode/ai/providers/openai-compatible/responses: see OpenCode issue #49670. Try @opencode/ai/providers/openai/responses with the same baseURL to retain Responses, or @opencode/ai/providers/openai-compatible to use Chat Completions.
- Requests reach /v1/chat/completions: use @ai-sdk/openai in v1, or @opencode/ai/providers/openai/responses in v2, to select Responses.
- Tool calls misbehaving: confirm the Gab model advertises capabilities.function_calling and that your OpenCode configuration enables tool support.
- Use https://gab.ai/v1 as baseURL. The adapter appends /responses or /chat/completions; do not append either endpoint yourself.
OpenCode Reference
Try a first prompt and follow-up
Select your configured Gab provider and model in OpenCode. Send the first prompt, then continue the same conversation with the follow-up.
For a workshop, income is USD 480 and base cost is USD 370. Reply with the remaining amount only.Expected result: USD 110.
Change only the base cost to USD 395. Keep income at USD 480 and reply with the new remaining amount only.Expected result after the change: USD 85.
Check the API connection separately
This cURL example checks Chat Completions directly. Use the in-client prompts above to check your OpenCode connection.
curl -sS https://gab.ai/v1/chat/completions \
-H "Authorization: Bearer $GAB_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "arya",
"messages": [
{
"role": "user",
"content": "For a workshop, income is USD 480 and base cost is USD 370. Reply with the remaining amount only, as USD 110."
}
],
"max_tokens": 1024,
"stream": false
}'API access and usage
Authenticated API requests require active Plus or Plus Premium and applicable credits. API use is billed separately from included in-app Chat. Daily request limits and credit balance are separate; the authentication reference explains allowances and reset times.
Resolve failed or incomplete requests
Read the client’s error and confirm its active provider, base URL and model. For key, account or rate-limit errors, use the authentication guide. If an answer stops early, inspect the completion status and output budget before retrying. For tool failures, check the selected model’s capabilities and the client’s tool configuration.