Search

Search HiAPI models, tools, and resources.

Back to blog
Tutorial8 min read

Claude Code and Codex on HiAPI: One Key, Two Tools

One HiAPI key powers both coding agents: Claude Code talks Anthropic Messages to Claude models, Codex talks Responses to GPT-6.1 — with copy-ready configs.

HiAPIClaude Opus 5.5GPT-6.1tutorialClaude Code

Back in February, Andrej Karpathy posted the line that is doing the rounds again this week: "the new default is that you are not writing the code directly 99% of the time, you are orchestrating agents who do and acting as oversight." The post introduced "agentic engineering" as the successor to vibe coding. On a No Priors episode in March he went further: "I don't think I've typed a line of code probably since December."

The numbers back him up. Claude Code's annualized run-rate went from roughly $17M in April 2025 to about $1B by late 2025, and past $2.5B by February 2026 (the Series G announcement figure, not audited ARR). In the JetBrains 2026 Developer Ecosystem survey (over 15,000 respondents, fielded May to July 2026), about 90% of professional developers use an AI coding agent weekly, with Claude Code's work adoption climbing from 18% to 39% (47% in the US) and Codex from 3% to 16%.

Which creates a very practical problem: more agents, but still one key and one billing flow per tool. Plenty of engineers now run Claude Code and Codex side by side, each with its own API key, its own top-ups, its own usage dashboard — and a fresh approval workflow every time they want to try a different model. This post shows how one HiAPI key serves both tools, and how to pick and switch models once they are connected.

The short version

  • One key, two tools: a single HiAPI API key authenticates Claude Code and Codex at the same time; balance, usage, and billing live in one dashboard.
  • Each tool on its strongest models: Claude Code speaks the Anthropic Messages API (/v1/messages) to HiAPI's Claude models; Codex speaks the Responses API (/v1/responses) to GPT-6.1-family models.
  • Freedom within two hard lines: Anthropic does not support routing Claude Code to non-Claude models through any gateway, so the right pattern is each tool on its own model family — not one tool running everything.
  • Five minutes to running: open the /connect/agents page, pick tool + model + OS, copy the generated config; Claude Code and Codex also support one-click CC Switch import.
  • Model swaps are one edit: change the model fields in settings.json for Claude Code, or one model line in hiapi.config.toml for Codex. The key never changes.

The HiAPI setup: one key, two tools

HiAPI is an API platform that aggregates multiple model families behind standard protocols. For coding agents it ships a dedicated onboarding page at /en/connect/agents ("Connect HiAPI to your agent"), covering Claude Code, Codex CLI, OpenCode, and Hermes Agent.

The protocol mapping is the part to get right:

ToolProtocolEndpointModels available on HiAPI
Claude CodeAnthropic Messages/v1/messagesclaude-opus-5-5, claude-sonnet-4-6, claude-opus-4-8, claude-opus-4-8@aws (4 total)
Codex CLIResponses API/v1/responsesgpt-6.1-sol, gpt-6.1-terra, gpt-6-astra, gpt-5.6 family, deepseek-v4 family (9 total)
OpenCode / Hermes AgentChat Completions/v1/chat/completionsBroadest coverage across text model families

So Claude Code — strongest at long-horizon coding agent tasks — gets the Claude family flagship, while Codex, built for throughput, gets the GPT-6.1 family. One key authenticates against both, and the billing merges into a single account.

One thing worth stating plainly: Anthropic officially does not support routing Claude Code to non-Claude models through any gateway. Pointing Claude Code at a GPT model makes tool calling and agent behavior unreliable, with no official support to fall back on. So "one key, switch models anytime" means routing tasks between two tools, each running the models it was built for — not mixing families inside one tool.

If you only care about Claude Code, we already have a dedicated single-tool walkthrough: "Using HiAPI with Claude Code: the full setup guide". This post focuses on running both tools off one key and the switching strategy that comes with it.

The fastest path is pure point-and-click:

  1. Open hiapi.ai/en/connect/agents.
  2. Pick a tool: Claude Code or Codex CLI.
  3. Pick a model — say claude-opus-5-5 on the Claude Code side, gpt-6.1-sol on the Codex side.
  4. Pick your OS (macOS / Windows / Linux); paths in the generated config follow it.
  5. Copy the config into the file it names, and you are done.

Claude Code and Codex support one-click CC Switch import: on HiAPI's API Keys page, hit import and your browser hands the config to CC Switch. The import link itself carries no credential — your key stays in a local environment variable.

Check versions first: Codex CLI requires 0.134 or newer (codex --version), and Claude Code should print a version via claude --version.

Option 2: write the config files by hand

Manual setup is two small files, one per tool.

Claude Code: ~/.claude/settings.json

Add this env block to ~/.claude/settings.json (on Windows, %USERPROFILE%\.claude\settings.json):

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.hiapi.ai",
    "ANTHROPIC_AUTH_TOKEN": "YOUR_HIAPI_API_KEY",
    "ANTHROPIC_MODEL": "claude-opus-5-5",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-5-5",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-opus-5-5",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-sonnet-4-6",
    "CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1"
  }
}

Field by field:

  • ANTHROPIC_BASE_URL points at https://api.hiapi.ai without /v1 — the client appends /v1/messages itself.
  • ANTHROPIC_AUTH_TOKEN takes your HiAPI API key, sent as a Bearer token.
  • ANTHROPIC_MODEL and the OPUS / SONNET aliases all point at the model you picked on HiAPI (HiAPI does not serve official Claude model IDs; the aliases resolve to your selection).
  • ANTHROPIC_DEFAULT_HAIKU_MODEL is pinned to claude-sonnet-4-6 — the slot Claude Code uses for background chores like context compaction and commit messages.
  • CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 avoids rejected requests: the new text pipeline refuses experimental beta fields.

Codex: ~/.codex/hiapi.config.toml

Create ~/.codex/hiapi.config.toml (Windows: %USERPROFILE%\.codex\hiapi.config.toml):

model_provider = "hiapi"
model = "gpt-6.1-sol"

[model_providers.hiapi]
name = "HiAPI"
base_url = "https://api.hiapi.ai/v1"
env_key = "HIAPI_API_KEY"
wire_api = "responses"

Then set the environment variable and launch:

export HIAPI_API_KEY="YOUR_HIAPI_API_KEY"
codex --profile hiapi

On Windows PowerShell: $env:HIAPI_API_KEY = "...". Note the base_url here includes /v1, unlike the Claude Code side — do not copy one into the other. wire_api = "responses" declares the Responses protocol, which Codex requires.

Picking models: Opus for hard tasks, GPT-6.1 for volume

With both tools connected, model choice becomes a routing decision. Our recommendation is simple:

  • Hard, long-horizon tasks go to claude-opus-5-5: cross-file refactors, marathon debugging sessions, anything that needs full-repo understanding. It is the Claude-side flagship with a 1M-token context window.
  • Everyday high-frequency work goes to gpt-6.1-sol / gpt-6.1-terra: batch rewrites, single-file features, script generation — high volume, modest per-task difficulty, and the price gap shows up fast on your invoice.
  • gpt-6-astra is the quality tier on the Responses side: a step up in price, enable it when the task justifies it.

Platform pricing for the key models ($/M tokens, as of October 2026, base tier):

ModelInputOutputCache readContext
claude-opus-5-5$2.02$10.08$0.101M
claude-sonnet-4-6$3.00$15.00$0.30—
gpt-6.1-sol$0.50$2.50$0.0251.05M
gpt-6.1-terra$0.25$1.25$0.01251.05M
gpt-6-astra$2.50$12.50$0.251.05M (long-context surcharge above 272K)

Look at the cache-read column. Agent sessions re-read the same repo over and over, and gpt-6.1-terra's cache reads cost $0.0125/M — real invoices on long iterative sessions land well below naive input-price estimates. Volume and cheap are not mutually exclusive.

For a deeper head-to-head on capability fit, see "Claude Opus 5.5 vs GPT-6.1 Sol"; the background on Terra's recent price cut is in "GPT-6.1 Terra Price Cut". Live pricing and specs live on the model detail page.

How easy switching actually is

This is the most underrated part of the setup. A model swap is two small actions:

  • Claude Code: edit the three fields ANTHROPIC_MODEL / ANTHROPIC_DEFAULT_OPUS_MODEL / ANTHROPIC_DEFAULT_SONNET_MODEL in ~/.claude/settings.json (on HiAPI the opus/sonnet aliases all resolve to your selection, so set them to the same new model ID) and start a fresh session.
  • Codex: edit the single model = "..." line in ~/.codex/hiapi.config.toml; the next codex --profile hiapi picks it up.

The key never moves. Compare that with the old path — a separate official key per tool, an approval cycle, secrets to rotate — and it is one edited line versus a small procurement project. If you imported via CC Switch, re-running the /connect/agents flow with a new model selected works too; it is all GUI.

Want more than these two families? OpenCode and Hermes Agent speak Chat Completions with the broadest model coverage, and the same page flow covers them. If multimodal and world-model work interests you, our "Genie 4 world model hands-on" is worth a read.

FAQ

Can Claude Code use GPT models through HiAPI?

No — and you do not want it to. Anthropic does not support routing Claude Code to non-Claude models through any gateway; forcing it makes tool calling and agent behavior unreliable with no official support. The Claude Code lineup on HiAPI is claude-opus-5-5, claude-sonnet-4-6, claude-opus-4-8, and claude-opus-4-8@aws. For GPT-6.1-family models, use the Codex side, where the Responses protocol supports them natively.

Can one HiAPI key serve both Claude Code and Codex at once?

Yes — that is the whole point. Both tools authenticate with the same key; only the mechanism differs (Claude Code uses ANTHROPIC_AUTH_TOKEN, Codex reads the HIAPI_API_KEY environment variable). Balance, usage, and billing sit in one dashboard, with per-tool usage breakdowns.

Is CC Switch import safe?

Yes. The import link carries no credential — your key stays in a local environment variable. The flow: create a key on HiAPI, hit CC Switch import on the API Keys page, and your browser hands the config to CC Switch. If you would rather not use the GUI, writing settings.json and hiapi.config.toml by hand is fully equivalent.

How do I verify both tools are actually connected?

On the Claude Code side, claude --version should print a version; send one message in a session and watch usage appear in the HiAPI dashboard. On the Codex side (CLI 0.134+), launch codex --profile hiapi, run one small task, and confirm metering in the dashboard. Run one small task in each tool first to confirm billing and the exact model ID before routing real volume.

Are OpenCode and Hermes Agent worth connecting?

Depends on your team's habits. Both speak Chat Completions, which has the broadest model-family coverage, and suit setups where one client must span multiple families. The config flow is identical: same /connect/agents page.

Does switching models affect in-flight sessions?

No. The change applies to new sessions; a running session keeps the model it started with. Start a fresh session after editing config. Session history is unaffected.

Key takeaways

Karpathy's 99% line is circulating again because agentic engineering is no longer an early-adopter game — it is the default way of working. Under that default, running Claude Code and Codex side by side becomes the norm, and fragmented keys and billing are real friction. HiAPI's answer is one key for two tools: Claude Code over the Messages API on the Claude flagship, Codex over the Responses API on the GPT-6.1 family, each on its strongest models, with merged billing. Onboarding is the /connect/agents config generator plus CC Switch import — five minutes to running — and a model swap is a one-line edit with the key untouched. Route hard tasks to Opus 5.5 and volume to GPT-6.1 Sol/Terra, and you hold both quality and invoice in check.

Generate it with HiAPI

Choose a model, enter your prompt, and see the result.

HiAPI Blog

Related articles

HiAPI

Generate it with HiAPI

Start generating