Use MiniMax in OpenCode and OpenAI Codex CLI
Complete opencode.json and ~/.codex/config.toml examples for running MiniMax-M2.7 and MiniMax-M3 through YiduoChan's OpenAI-compatible endpoint at https://yiduochan.com/v1, with verification commands, per-token prices and troubleshooting.
OpenCode and OpenAI Codex CLI are terminal coding agents that can be pointed at any OpenAI-compatible endpoint. YiduoChan serves MiniMax text models through exactly that interface at https://yiduochan.com/v1, so wiring either tool up is one short config file. This page gives complete, copy-ready configurations for both tools, a way to verify the connection before you start a session, the current per-token prices, and fixes for the errors you are most likely to hit.
What you are configuring
Both tools send standard chat completion requests (messages, tool definitions, streaming) to /v1/chat/completions and authenticate with a Bearer token. YiduoChan accepts that request shape unchanged, so no local proxy or wrapper is needed. The text model IDs are MiniMax-M2.7, MiniMax-M2.7-highspeed and MiniMax-M3; they are case-sensitive and must be used exactly as written.
- Base URL:
https://yiduochan.com/v1 - Endpoints used by coding agents:
/v1/chat/completionsand/v1/models - Auth header:
Authorization: Bearer <API key from the console> - Billing: prepaid USD credits, pay-as-you-go, no subscription; failed requests are never charged
If you use Claude Code instead of, or alongside, these tools, the Anthropic-compatible setup is documented separately at MiniMax in Claude Code. The same API key works for all three.
Prerequisites
- Create an account at /register and top up. Accounts are prepaid; the minimum top-up is $5 and there are no free credits.
- Generate an API key in the console.
- Export the key in the shell that will launch the agent. Both configurations below read it from the
YIDUOCHAN_API_KEYenvironment variable, so the key never lands in a config file that might be committed.
export YIDUOCHAN_API_KEY="sk-..."
Add that line to ~/.zshrc or ~/.bashrc if you want it to persist across terminals. The variable has to be present in the process environment of the CLI; a .env file that your shell does not source will not be seen.
OpenCode: custom OpenAI-compatible provider
OpenCode reads opencode.json from the project root, or globally from ~/.config/opencode/opencode.json. Custom providers are declared under the provider key. For an OpenAI-compatible endpoint the provider uses the @ai-sdk/openai-compatible npm package, which OpenCode installs on first use.
Complete opencode.json
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"yiduochan": {
"npm": "@ai-sdk/openai-compatible",
"name": "YiduoChan",
"options": {
"baseURL": "https://yiduochan.com/v1",
"apiKey": "{env:YIDUOCHAN_API_KEY}"
},
"models": {
"MiniMax-M2.7": {
"name": "MiniMax-M2.7"
},
"MiniMax-M2.7-highspeed": {
"name": "MiniMax-M2.7-highspeed"
},
"MiniMax-M3": {
"name": "MiniMax-M3 (1M context)"
}
}
}
},
"model": "yiduochan/MiniMax-M2.7"
}
Field by field:
npmselects the provider implementation.@ai-sdk/openai-compatiblespeaks the plain chat completions protocol. Do not substitute@ai-sdk/openai, which targets OpenAI's Responses API by default; that API is not part of the YiduoChan endpoint.options.baseURLis the versioned root,https://yiduochan.com/v1. OpenCode appends/chat/completionsitself.options.apiKeyuses OpenCode's{env:NAME}substitution, so the value is read fromYIDUOCHAN_API_KEYat startup.- The keys under
modelsare the model IDs sent on the wire and must match YiduoChan's IDs exactly. Thenamevalues are display labels and can be anything. modelsets the session default asprovider/model-id. Change it toyiduochan/MiniMax-M3when you need the 1,048,576-token context window.
Running OpenCode against MiniMax
- Save the file and start
opencodein the project directory. - Type
/modelsin the TUI to confirm the three YiduoChan entries are listed; the same command switches models mid-session. - Run a small task, for example asking the agent to list the files in the repository, and check that the response streams back without an error banner.
You can also print the merged provider list from the shell with opencode models, which is a quick way to confirm that the JSON parsed and the provider was registered.
Codex CLI: model_providers in config.toml
OpenAI Codex CLI is configured through ~/.codex/config.toml. A custom provider is a table under model_providers; the top-level model and model_provider keys then select it as the default. Because YiduoChan serves the chat completions protocol, the provider must set wire_api = "chat". The default "responses" value would send requests to a path that does not exist on this endpoint.
Complete ~/.codex/config.toml
# Default model and provider
model = "MiniMax-M2.7"
model_provider = "yiduochan"
[model_providers.yiduochan]
name = "YiduoChan"
base_url = "https://yiduochan.com/v1"
env_key = "YIDUOCHAN_API_KEY"
wire_api = "chat"
# Optional: a profile for the 1M-context model
[profiles.m3]
model = "MiniMax-M3"
model_provider = "yiduochan"
base_urlmust include/v1. Codex appends/chat/completionswhenwire_apiis"chat".env_keynames the environment variable that holds the API key. Codex reads it at startup and sends it as a Bearer token; there is no separatecodex loginstep for a custom provider.modelis passed through verbatim, so it must be one ofMiniMax-M2.7,MiniMax-M2.7-highspeedorMiniMax-M3.- The
[profiles.m3]table is optional. It keeps M2.7 as the default and lets you start a long-context session withcodex --profile m3without editing the file.
Running Codex CLI
- Confirm the key is exported:
echo $YIDUOCHAN_API_KEYshould print your key. - Start an interactive session with
codex, or run a one-shot task withcodex exec "summarize this repository". - To override the model for a single run without touching the config, pass
codex -m MiniMax-M3.
Codex applies the same provider to every subcommand, so a codex exec step in a CI job needs only the exported variable and the config file; nothing else changes between interactive and non-interactive use.
Verify the endpoint before starting a session
If either tool fails, first confirm that the endpoint and key work independently of the agent. Two curl calls are enough.
curl -s https://yiduochan.com/v1/models \
-H "Authorization: Bearer $YIDUOCHAN_API_KEY"
The response is a JSON list whose id fields should include MiniMax-M2.7, MiniMax-M2.7-highspeed and MiniMax-M3. Then send a minimal completion:
curl -s https://yiduochan.com/v1/chat/completions \
-H "Authorization: Bearer $YIDUOCHAN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "MiniMax-M2.7",
"messages": [{"role": "user", "content": "Reply with the single word: ok"}]
}'
A 200 response with a choices[0].message.content field means the key, base URL and model ID are all correct, and any remaining problem is in the tool's config file rather than the account.
Models and prices
All three text models are billed per token in USD at MiniMax list-level pricing. Prices below are per 1M tokens. Cache writes on MiniMax-M2.7 and MiniMax-M2.7-highspeed are $0.375 per 1M tokens.
| Model ID | Input | Output | Cache read | Notes |
|---|---|---|---|---|
MiniMax-M2.7 | $0.30 | $1.20 | $0.06 | Default choice for agent sessions |
MiniMax-M2.7-highspeed | $0.60 | $2.40 | $0.06 | Same quality, lower latency |
MiniMax-M3, prompt up to 512K tokens | $0.30 | $1.20 | $0.06 | 1,048,576-token context |
MiniMax-M3, prompt 512K to 1M tokens | $0.60 | $2.40 | $0.12 | Tier set by prompt length |
Which model to pick
MiniMax-M2.7is the sensible default for both tools. Details are on the MiniMax-M2.7 page.MiniMax-M2.7-highspeedreturns the same quality at lower latency for double the per-token price. Use it for interactive sessions where wait time matters more than cost.MiniMax-M3is for sessions whose context outgrows M2.7: large monorepos, long agent transcripts, or whole-codebase questions. Up to 512K prompt tokens it costs the same as M2.7; above that the higher tier applies. See the MiniMax-M3 page.
Switching models does not change the config shape; only the model ID differs. Declaring all three in the same provider costs nothing and lets you move between them per task.
Agent tools re-send the growing conversation on every turn, so input tokens dominate the bill. Input served from cache is billed at the cache-read rate, $0.06 per 1M tokens on M2.7 and on M3 up to 512K, which is why the per-turn cost of a long session stays well below the headline input price. The full price list, including the speech models, is on /pricing; an overview of every MiniMax model on the platform is at /minimax/.
Troubleshooting
401 Unauthorized
The key is missing or wrong. Run echo $YIDUOCHAN_API_KEY in the same terminal that launches the tool. OpenCode's {env:...} substitution and Codex's env_key both resolve at process start, so a variable exported after launch is not seen; restart the tool. A key that was revoked in the console also returns 401, so generate a fresh one if the variable is set but rejected.
Model not found
Model IDs are case-sensitive: MiniMax-M2.7 works, minimax-m2.7 and MiniMax-M2-7 do not. In OpenCode the ID is the object key under models; in Codex it is the value of model. Compare against the output of /v1/models.
404 or an empty response from Codex
Almost always wire_api is missing or set to "responses". Set wire_api = "chat" in the provider table. Also check that base_url ends in /v1 and not in /v1/chat/completions; Codex appends the path itself and a doubled path returns 404.
OpenCode does not list the provider
Validate the JSON (a trailing comma is the usual cause) and confirm the file is either in the project root or at ~/.config/opencode/opencode.json. The npm value must be exactly @ai-sdk/openai-compatible. Run opencode models to see whether the provider was registered.
Insufficient balance
Credits are prepaid. A request that fails for any reason, including insufficient balance, is not charged. Top up from the console; presets are $5, $10, $20, $50, $100, $200 and $500, or any custom amount with a $5 minimum, and credits stay valid for 12 months.
Long sessions slow down or hit the context limit
Switch to MiniMax-M3 for the 1,048,576-token context window: yiduochan/MiniMax-M3 in OpenCode, codex --profile m3 or codex -m MiniMax-M3 in Codex. Alternatively use each tool's /compact command to shorten the transcript and stay on M2.7.
Billing at a glance
- Prepaid USD credits, pay-as-you-go, no subscription.
- Minimum top-up $5; credits valid for 12 months.
- Failed requests are never charged.
- Standard OpenAI and Anthropic-compatible APIs; one key covers OpenCode, Codex CLI and Claude Code.
Questions about a specific configuration or an unexpected charge can be sent to [email protected].
FAQ
Does OpenCode support MiniMax through a custom OpenAI-compatible provider?
Yes. Declare a provider in opencode.json with "npm": "@ai-sdk/openai-compatible", baseURL https://yiduochan.com/v1 and the API key read from an environment variable; MiniMax-M2.7, MiniMax-M2.7-highspeed and MiniMax-M3 then appear under /models.
How do I add a custom model provider to Codex CLI's config.toml?
Add a [model_providers.yiduochan] table to ~/.codex/config.toml with base_url = "https://yiduochan.com/v1", env_key = "YIDUOCHAN_API_KEY" and wire_api = "chat", then set model = "MiniMax-M2.7" and model_provider = "yiduochan" at the top of the file.
Why does Codex CLI return 404 with my custom base_url?
Codex defaults to the Responses API; set wire_api = "chat" so it calls /v1/chat/completions, and make sure base_url ends with /v1 rather than the full completions path.
What does MiniMax-M2.7 cost when used from OpenCode or Codex CLI?
$0.30 per 1M input tokens and $1.20 per 1M output tokens, with cache reads at $0.06 and cache writes at $0.375 per 1M tokens; the full list is on /pricing.
Which MiniMax model should I use for a large repository?
MiniMax-M3 has a 1,048,576-token context window and costs the same as MiniMax-M2.7 for prompts up to 512K tokens; see /minimax/m3/.
Do I need a subscription to use MiniMax with these tools?
No. YiduoChan is prepaid pay-as-you-go in USD with a $5 minimum top-up and no subscription, and failed requests are never charged; sign up at /register.