Usar apimodels no OpenAI Codex
Two separate things: to have Codex generate video, images and voice-over, install the apimodels plugin (sign in once, two commands, whatever model Codex runs on); to run Codex itself on apimodels GPT-6 Sol / Luna, write one config.toml (the CLI and the desktop app share it). This page covers both, which models Codex can use, pricing, a curl sanity check and the common errors.
TL;DR
Use wire_api = "responses", base_url = "https://api.apimodels.app/v1", model = "gpt-6-sol" (or "gpt-6-luna" for a lower per-token price), and put your API key in the env var. The model setting only takes chat models — for video or images, add the apimodels MCP server and just ask Codex to generate them.
Fastest: the apimodels plugin for video and images
Codex does the planning — script, shot list, prompts, editing with ffmpeg; the plugin renders the video, images and voice-over. It ships with a skill, so Codex decides on its own when to use it, which model to pick, how long video takes and when to ask you before a batch — just ask in plain words. The plugin does not change the model Codex runs on; it works with a ChatGPT sign-in too.
1. Sign in once: your browser opens apimodels.app, click Authorize, and the key is saved on this machine — nothing to copy or paste
npx -y apimodels-mcp login2. Install the plugin, then restart Codex
codex plugin marketplace add stimQQ/apimodels-mcp
codex plugin add apimodels@apimodelsOnly have the Codex desktop app and no codex command in your terminal? Replace codex with npx -y @openai/codex: it runs the official CLI on the fly and shares the desktop app's config.
3. Just ask, e.g. "make a 5-second 16:9 video of a kitten slowly raising its head in morning light". Generating video, images or speech spends credits, so Codex asks you to confirm each call; checking progress or the balance never asks.
Node.js is required. If it is missing, install the plugin anyway and ask for something: Codex installs the official Node.js for you once you agree (on Windows click Yes in the system prompt; on macOS click Continue, then Install), then restart Codex. Codex can also run the sign-in step for you; you only click Authorize in the browser.
Comece a funcionar em 3 passos
- 1
Obtenha uma chave API
Abra Console no seu console e crie uma chave sk_….
- 2
Adicione a configuração
Paste the snippet below into ~/.codex/config.toml (create it if needed; on Windows it lives in C:\Users\<you>\.codex\).
- 3
Set the key + start
Put your key in the env var, then (re)open Codex.
Configuração completa
~/.codex/config.toml
# ~/.codex/config.toml — drop-in, paste as-is
model_provider = "apimodels"
model = "gpt-6-sol" # or "gpt-6-luna" (lowest-priced) / "gpt-5.5"
review_model = "gpt-6-sol" # model used by /review
model_reasoning_effort = "medium" # low | medium | high
disable_response_storage = true
[model_providers.apimodels]
name = "apimodels"
base_url = "https://api.apimodels.app/v1"
wire_api = "responses"
env_key = "APIMODELS_API_KEY"Shell
# put your apimodels key in the env var the config points at,
# then launch codex (add this line to ~/.zshrc to make it stick):
export APIMODELS_API_KEY="sk_…your_key…"
codex
# Windows (PowerShell or cmd) — then reopen Codex:
setx APIMODELS_API_KEY "sk_…your_key…"Referência de configuração
| Configuração | Valor | Por quê |
|---|---|---|
| wire_api | responses | Codex's native mode: every turn goes to /v1/responses, which carries reasoning and multi-turn tool state. |
| base_url | https://api.apimodels.app/v1 | Our shared /v1 endpoint prefix, no trailing slash. |
| model | gpt-6-sol / gpt-6-luna / gpt-5.5 | Must be a chat model on /v1/responses — see the next section. gpt-5.5 works with a dot or a dash (gpt-5-5). |
| review_model | gpt-6-sol | Model used by the /review command. Optional — defaults to model above. |
| model_reasoning_effort | low / medium / high | Codex turns this into the request-body reasoning.effort field — see below. |
| env_key | APIMODELS_API_KEY | Qualquer nome — o Codex apenas lê a variável de ambiente que você indicar. |
| model_provider | apimodels | Deve corresponder à chave da tabela [model_providers.<name>] abaixo. |
Which models Codex can use
The model setting is the model Codex itself uses to talk, read and edit code, and every turn goes through /v1/responses. So it only takes chat models on that endpoint; anything else returns HTTP 400 with the reason in the error message.
| Recommended | gpt-6-sol · gpt-6-luna · gpt-5.5 | The most-used, best-proven models on /v1/responses. gpt-6-sol as the everyday default, gpt-6-luna for the lowest per-token price. |
| Also works | gpt-6-astra · gpt-5.6-* · grok-4.6 · qwen3.8 · deepseek-v4 · glm-5.2 | Also served on /v1/responses. Most traffic on this endpoint is the GPT family; the others see far less. |
| Not available | Claude · Gemini | They are only on /v1/chat/completions, and Codex only uses /v1/responses. |
| Not available | Video / image / speech models | They are not chat models. To make video or images from Codex, use the MCP server below. |
Without the plugin: configure the MCP server by hand
Video and image models can't go in model, but Codex can call them as tools. Without the plugin, add our MCP server, apimodels-mcp, to the same config.toml and Codex gains generate_video, generate_image, text_to_speech and more, covering every video and image model on the site. Node.js must be installed (it runs through npx). After the login command above, the env line can go.
# add to the same ~/.codex/config.toml
[mcp_servers.apimodels]
command = "npx"
args = ["-y", "apimodels-mcp"]
env = { APIMODELS_API_KEY = "sk_…your_key…" }
# tool_timeout_sec = 660 # optional: lets one call wait for the whole videoRestart Codex and ask. Without the plugin's skill Codex may not go looking for these tools, so name the tool in your request:
Use apimodels generate_video with grok-imagine-video-1.5 to make a 10-second 16:9 video:
a golden tabby kitten slowly raises its head in warm morning light.Video takes a while: a median of about 2.5 minutes, 9 in 10 within 8 minutes. Codex aborts a tool call after 60 seconds by default, so each call waits at most 50 seconds and then hands back a task id; Codex calls get_task on its own until it has the video URL. Nothing is resubmitted or billed twice.
On Windows, if the MCP server does not start, launch it through cmd:
# Windows: if the MCP server does not start, launch npx through cmd
[mcp_servers.apimodels]
command = "cmd"
args = ["/c", "npx", "-y", "apimodels-mcp"]
env = { APIMODELS_API_KEY = "sk_…your_key…" }All tools, parameters and env vars are in /docs/mcp.
Esforço de raciocínio
Reasoning depth is the reasoning.effort field in the request body (Codex sets it via model_reasoning_effort), not a model-name suffix. All levels share the same per-token price; higher effort just emits more reasoning_tokens (billed as part of output_tokens). When calling the API directly, pass "reasoning": { "effort": "high" }.
| reasoning.effort | Usar para |
|---|---|
| low | Conclusões rápidas / de etapa única / simples |
| medium | Refatorações de várias etapas, decisões de design |
| high | Depuração difícil, análise entre arquivos |
Preços
Output tokens include reasoning tokens. Each call is billed against your apimodels balance at the price on the model page. Video and images are billed separately at their own model-page prices. Other chat models are listed in /docs/llm.
Verificação rápida de 30 segundos
Before setting up Codex, confirm the endpoint and your key work with a single curl:
curl -s https://api.apimodels.app/v1/responses \
-H "Authorization: Bearer $APIMODELS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6-luna",
"input": "Reply with exactly: ok",
"reasoning": { "effort": "low" },
"max_output_tokens": 16
}'Resposta esperada (truncada):
{
"id": "resp_...",
"object": "response",
"status": "completed",
"output": [{
"type": "message",
"role": "assistant",
"content": [{ "type": "output_text", "text": "ok" }]
}],
"usage": { "input_tokens": 22, "output_tokens": 5, "total_tokens": 27 }
}HTTP 200 with output[].content[0].text === "ok" means you're good to go.
responses or chat?
Codex uses wire_api = "responses" — its native mode, which handles reasoning and multi-turn tool calls most cleanly — so pick responses for Codex. That also sets which models Codex can use: Claude and Gemini are only on /v1/chat/completions, and work as usual in clients that speak chat format (Cherry Studio, Cursor and the like).
Solução de problemas
| Sintoma | Causa / correção |
|---|---|
| HTTP 401 Invalid or missing API key | The env var is not set, or the key was disabled. Set APIMODELS_API_KEY again and reopen Codex, or mint a new key in the console. |
| HTTP 400 … is a video generation model / is not available on /v1/responses | model is set to a video, image or speech model, or to Claude / Gemini. Set model to gpt-6-sol or gpt-6-luna; for video or images use the MCP server above. |
| HTTP 400 Unknown model | Model name typo. Use gpt-6-sol / gpt-6-luna / gpt-5.5; the full list is at GET https://api.apimodels.app/v1/models. |
| 404 / endpoint não encontrado | Wrong base_url — it must be https://api.apimodels.app/v1 (with /v1, no trailing slash). Codex appends /responses itself. |
| generate_video and friends never show up in Codex | Check the plugin is installed (apimodels@apimodels appears in codex plugin list) and that you restarted Codex; check Node.js is installed (npx -v prints a version); run npx -y apimodels-mcp status to see whether you are signed in. With a hand-written config, try the cmd /c form above on Windows and restart Codex after editing config.toml. |
| The tool call gets aborted mid-video | Codex aborts a tool call after 60 seconds by default. Since 0.3.0, apimodels-mcp waits at most 50 seconds per call and hands back a task id for get_task. On an older version, change the package in args to apimodels-mcp@latest and restart Codex. Or set tool_timeout_sec so one call waits for the whole video. |
| Resposta vazia ou apenas raciocínio sem texto visível | max_output_tokens too small — reasoning tokens ate the budget. Leave several hundred tokens for high. |
| Cobrança maior do que o esperado | output_tokens includes reasoning_tokens — at effort high these can be many times the visible output. Pick the lowest effort that meets your quality bar, and move high-volume work to gpt-6-luna. |