MegaBrain University · guide
Kilo Code with a Custom OpenAI-Compatible Provider: Claude, GPT-6 and Open Models
Updated · 10 min setup
Short answer
To use Kilo Code with MegaBrain, open Settings → Providers → Custom provider, choose OpenAI Compatible, set the base URL to https://getmegabrain.com/api/gateway/v1, paste your MegaBrain key and fetch the models. In the Kilo CLI, add the same provider to ~/.config/kilo/kilo.jsonc. Kilo then codes with Claude, GPT-6, Kimi or GLM on one key.
| Base URL (OpenAI-compatible) | https://getmegabrain.com/api/gateway/v1 |
|---|---|
| Base URL for Claude Code and the Anthropic SDK | https://getmegabrain.com/api/anthropic |
| Key | Authorization: Bearer <key> — the API key page in your dashboard |
| Default model | anthropic/claude-sonnet-5.5 |
| Free model for testing | mb-auto/free |
What is Kilo Code
Kilo Code is an open-source AI coding agent for VS Code and JetBrains IDEs, with a terminal version, the Kilo CLI (a fork of OpenCode). It plans, edits files, runs commands, uses MCP servers and switches between agent modes.
Kilo can talk to any OpenAI-compatible API through a custom provider. Connecting MegaBrain gives it every major model behind one key and one balance, so you can put a frontier model on architecture work and a cheap one on routine edits.
Setup, step by step
Step 1. Get a MegaBrain API key
Sign up with GitHub, Google or email, add funds on the Balance page and create a key on the API key page. The key works for every text, image and video model, and each request is paid from your balance — no subscription.
Put the key in an environment variable so it never lands in a config file you share:
# ~/.zshrc or ~/.bashrc export MEGABRAIN_API_KEY="your-megabrain-key"curl https://getmegabrain.com/api/gateway/v1/chat/completions \ -H "Authorization: Bearer $MEGABRAIN_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model": "anthropic/claude-sonnet-5.5", "messages": [{"role": "user", "content": "Say OK"}]}'Check the key before you touch the agent. A JSON reply with
choicesmeans the key, the balance and the model all work:Step 2. Install Kilo Code
In VS Code or a JetBrains IDE, install Kilo Code from the extension marketplace. For the terminal:
npm install -g @kilocode/cli(the command iskilo).Step 3. Add MegaBrain in the extension
Open Kilo’s settings (gear icon) → Providers → Custom provider and fill in:
Provider ID: megabrain Display name: MegaBrain Provider API: OpenAI Compatible Base URL: https://getmegabrain.com/api/gateway/v1 API key: your-megabrain-key Models: Fetch models (or type anthropic/claude-sonnet-5.5)Click Submit, then choose MegaBrain → anthropic/claude-sonnet-5.5 in the model picker.
Step 4. Or configure the Kilo CLI
The CLI reads
~/.config/kilo/kilo.jsonc. Keep the key in the global file: Kilo ignores{env:…}in project config.{ "$schema": "https://app.kilo.ai/config.json", "model": "megabrain/anthropic/claude-sonnet-5.5", "provider": { "megabrain": { "npm": "@ai-sdk/openai-compatible", "name": "MegaBrain", "options": { "baseURL": "https://getmegabrain.com/api/gateway/v1", "apiKey": "{env:MEGABRAIN_API_KEY}" }, "models": { "anthropic/claude-sonnet-5.5": { "name": "Claude Sonnet 5.5", "tool_call": true, "limit": { "context": 1000000, "output": 32000 } }, "moonshotai/kimi-k3.1-pro": { "name": "Kimi K3.1 Pro", "tool_call": true, "limit": { "context": 1048576, "output": 32000 } } } } } }Set
tool_call: true(without it, file edits and the terminal tool do not work) andlimit.context(without it, Kilo never compacts a long conversation). Runkilo, then/modelsto switch.
Which model to choose
Claude Sonnet 5.5 is the default for coding in Kilo. Use Opus 5.5 or GPT-6.1 Sol for architecture and hard bugs, Kimi K3.1 Pro or GLM 5.3 for everyday edits, DeepSeek V4.1 Flash for bulk mechanical changes.
| Model ID | When to use it |
|---|---|
anthropic/claude-sonnet-5.5 | The default for an agent: reliable tool calls, holds long tasks, 1M-token context. |
anthropic/claude-opus-5.5 | Hard multi-step work, code review and analysis where a mistake costs more than tokens. |
openai/gpt-6.1-sol | OpenAI's flagship: the alternative to Claude for code and reasoning. |
google/gemini-3.8-flash | Fast and cheap: long documents, spreadsheets, inbox triage. |
moonshotai/kimi-k3.1-pro | A strong open-weight model for agents and code. |
z-ai/glm-5.3 | Open-weight model for code and tools with good price-to-quality. |
deepseek/deepseek-v4.1-flash | High-volume routine work: classification, drafts, summaries. |
mb-auto/free | Free, for checking your setup. 128K context, weaker at tool calls; do not send confidential data. |
Every model with its price and context window is in the catalog. They all work with the same key.
What you can do
Agent modes
Switch between planning, coding, debugging and asking; each mode can use its own model from the MegaBrain provider.
MCP servers
Add MCP servers in kilo.jsonc to give the agent your database, issue tracker or docs.
IDE and terminal, one config
The extension and the Kilo CLI share providers and models, so a team sets MegaBrain up once.
Any OpenAI-compatible model
Models are fetched from MegaBrain’s /models, so new releases appear without reinstalling anything.
Business use cases
Coding assistant for a team without vendor sprawl
Every developer gets a MegaBrain key instead of separate Anthropic, OpenAI and Google accounts; usage per key is visible in one dashboard.
Legacy code modernisation
Plan the migration with Opus 5.5, then let Kimi or GLM do file-by-file changes in code mode — the expensive model only where it pays off.
Task for the agent:
Plan the migration of this Express 4 app to Express 5: list breaking changes that affect us, with file paths. Then, file by file, apply the changes and run the tests after each file.Tests and docs on autopilot
A cheap model writes missing unit tests and docstrings across the repo; a frontier model reviews the diff before merge.
Shipping AI features
When the product itself needs AI, the same key covers the app’s text calls and MegaBrain’s image and video API.
Troubleshooting
401 Unauthorized
The key is missing or mistyped, or the agent did not read the environment variable (restart the agent after export). Test the key with the curl command from step 1.
402 Payment Required
The balance is empty. Add funds on the Balance page, or switch to mb-auto/free to keep testing.
Model not found
The model ID must match the catalog exactly, including the lab prefix: anthropic/claude-sonnet-5.5, not claude-sonnet-5.5. The base URL must end in /v1.
“Fetch models” returns nothing
Check the base URL ends in /v1, then type the model ID by hand (anthropic/claude-sonnet-5.5).
Empty answers from a reasoning model
A reasoning model can spend the whole output budget thinking. Raise limit.output or use a non-reasoning model for that mode.
FAQ
Can Kilo Code use Claude without an Anthropic key?
Yes. Add MegaBrain as a custom provider and pick anthropic/claude-sonnet-5.5 or anthropic/claude-opus-5.5; requests are paid from your MegaBrain balance.
Which Provider API should I choose?
OpenAI Compatible with the base URL https://getmegabrain.com/api/gateway/v1. It is the format every MegaBrain model supports.
How much does it cost?
You pay per token at each model’s price, from a prepaid balance in US dollars topped up by card. There is no subscription and no seat fee, so an agent that sits idle costs nothing. Prices per million tokens are in the model catalog; mb-auto/free costs nothing at all.
Do I need separate Anthropic, OpenAI or Google accounts?
No. One MegaBrain key reaches Claude, GPT, Gemini, Grok, Kimi, GLM, DeepSeek, Qwen and MiniMax. You switch models by changing the model ID, not the provider or the key.
Does the same setup work in JetBrains?
Yes. The Kilo Code plugin for JetBrains IDEs has the same Providers settings; enter the same base URL, key and model.
MegaBrain · one API for every model
Claude, GPT, Gemini, Kimi, GLM and DeepSeek in any agent — one key, one balance.
Sign up, add funds by card and pay only for what your agents use. No subscription. Free models work without a key.