AICredits logo
Integrations

OpenCode

Route OpenCode terminal coding-agent requests through AICredits with a custom OpenAI-compatible provider.

Use this page with an AI assistant

Opens a new chat with this docs URL and the correct AICredits base URLs.

OpenCode is a terminal-based, provider-agnostic coding agent CLI. Configure an OpenAI-compatible provider so repository reads, edits, and agent loops route through AICredits.

Provider Setup

Add AICredits to ~/.config/opencode/config.json:

{
  "provider": {
    "aicredits": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "AICredits",
      "options": {
        "baseURL": "https://api.aicredits.in/v1",
        "apiKey": "sk-your-aicredits-key"
      },
      "models": {
        "openai/gpt-4o-mini": {},
        "anthropic/claude-sonnet-4.5": {},
        "google/gemini-2.5-flash": {}
      }
    }
  },
  "model": "aicredits/openai/gpt-4o-mini"
}

If you prefer environment variables, keep the key out of the config file:

export AICREDITS_API_KEY="sk-your-aicredits-key"

Then reference that variable from your OpenCode provider if your version supports environment interpolation.

Start with openai/gpt-4o-mini for planning and small edits. Switch to anthropic/claude-sonnet-4.5 for multi-file coding sessions, or google/gemini-2.5-flash for long-context repository reads.

Verify

Ask OpenCode:

Reply with "AICredits via OpenCode" and do not edit files.

Then check Dashboard -> Usage.

Troubleshooting

OpenCode cannot find the provider - Confirm the provider name and selected model use the same aicredits prefix in your config.

Requests go to another provider - Check the active model in OpenCode and confirm the base URL is https://api.aicredits.in/v1.

Model not available - Use an exact model ID from Models.

On this page