How to use open models with Claude Code Nebius published a cookbook showing how to run open coding models such as moonshotai/Kimi-K2.7-Code behind Anthropic's Claude Code CLI using nebiusrelay, a local proxy that translates Anthropic Messages API calls into the OpenAI-compatible chat-completions format served by Nebius Token Factory. The relay, which runs on Bun and installs to ~/.nebiusrelay/, leaves Claude Code unmodified; a measured headless task that wrote one file took 22 seconds and cost $0.032 for 30,873 input and 609 output tokens. The one-shot prompt reproduces the translation in about 280 lines of standard-library Python, and Kimi K2.7 Code offers a 262K context window and is text-only, built for agentic coding. Claude Code only speaks the Anthropic Messages API, and Token Factory serves its open coding models through an OpenAI-compatible API. Claude Code reads its endpoint from the environment, so a local translation proxy is enough to run Kimi, Qwen, MiniMax, or DeepSeek behind the CLI you already use, with no change to the agent itself. This cookbook does that two ways: with nebiusrelay , the proxy Nebius links for Claude Code https://github.com/nebius/token-factory-cookbook/tree/main/coding , and, through the one-shot prompt, with a relay you build yourself. What you will build what-you-will-build What you will build A working Claude Code session whose every token is served by an open model on Token Factory: - moonshotai/Kimi-K2.7-Code https://tokenfactory.nebius.com/models/catalog/text2text/moonshotai%2FKimi-K2.7-Code as the coding model: 262K context, text-only, built for agentic coding. - nebiusrelay as the local Anthropic-to-Token-Factory translator, injected for one run at a time. - Claude Code itself , unmodified. Your login, subscription, settings, and CLAUDE.md files stay exactly as they are. A measured headless task that wrote one file took 22 seconds and cost $0.032 for 30,873 input and 609 output tokens. Why Claude Code needs a proxy at all why-claude-code-needs-a-proxy-at-all Why Claude Code needs a proxy at all Cursor, Cline, and OpenCode can point straight at Token Factory because they speak the OpenAI chat-completions format Token Factory serves. Claude Code speaks Anthropic Messages: a different request shape, a different response shape, and a different server-sent-event vocabulary for streaming. The relay accepts Anthropic Messages on localhost , rewrites each request into chat-completions, and rewrites the reply, including tool calls, back into Anthropic blocks. The one-shot prompt build-the-relay-yourself reproduces that translation in about 280 lines of standard-library Python. Prerequisites prerequisites Prerequisites - macOS or Linux, and curl - Claude Code https://claude.com/claude-code already installed. The relay routes it but does not install it. - A Nebius Token Factory https://tokenfactory.nebius.com/ account and API key https://tokenfactory.nebius.com/?modals=create-api-key - The key in an environment variable, never pasted into a tracked file nebiusrelay runs on Bun https://bun.sh/ and installs it for you if it is missing. Run the cookbook run-the-cookbook Run the cookbook 1. Install the relay. It writes to ~/.nebiusrelay/ , links the wrappers into a writable directory already on your PATH , and adds a PATH line to your shell profile: curl -fsSL https://nebius-tf-relay.vercel.app/install.sh | sh Read the script before piping it to a shell if you have not seen it before. Then restart your shell, or run the export PATH=... line it prints, and confirm the install: nebiusrelay --version 2. Give it your Token Factory key. Either store it once, interactively: nebiusrelay configure or export it and skip the prompts, which is the form to use in CI or from another agent: export NEBIUS API KEY="your-token-factory-key" 3. Launch Claude Code on an open model. Put --main before the claude subcommand. The troubleshooting section explains why the order matters: nebiusrelay --main moonshotai/Kimi-K2.7-Code claude The banner confirms where your tokens are going before the session starts: Nebius TF Relay ▸ Routing Claude Code → Nebius Token Factory Kimi K2.7 Code . Not Anthropic. Omit --main and you get the relay’s built-in default, which is Kimi K2.7 Code in v0.14.3. The short alias nclaude is the same thing with no model flag. 4. Run one headless task so that success is a file on disk. Close stdin with < /dev/null ; without it a non-interactive run blocks waiting for input: nebiusrelay --main moonshotai/Kimi-K2.7-Code claude \ -p "Use the Write tool to create hello.py whose only line is: print 'relay ok' " \ --dangerously-skip-permissions --output-format json < /dev/null --dangerously-skip-permissions stops a headless run from stalling on a permission prompt. Use it only in a throwaway directory. Verify the result verify-the-result Verify the result The file exists, with the right contents. This shows that tool calls survived the translation in both directions: cat hello.py The tokens came from Token Factory. The relay prints a cost line when the session ends, priced against the model’s real per-token rates: nebiusrelay cost session total: $0.0318 30,873 in, 609 out For history across sessions, all of it stored locally under ~/.nebiusrelay and never uploaded: nebiusrelay usage --last 7d Switching models works. Run the same task again against a different one and watch the banner change: nebiusrelay --main moonshotai/Kimi-K2.6 claude -p "reply with OK only" \ --dangerously-skip-permissions < /dev/null Every model your account can see is available here, including moonshotai/Kimi-K3 , Qwen/Qwen3.5-397B-A17B , MiniMaxAI/MiniMax-M3 , deepseek-ai/DeepSeek-V4-Pro , and zai-org/GLM-5.2 , because the relay pulls the catalog from Token Factory at startup. Troubleshooting troubleshooting Troubleshooting - --main seems to be ignored. nclaude --main X and nebiusrelay claude --main X both put the flag after the harness name, where it is passed through to Claude Code and dropped, so the run silently uses the default model. The banner names the model actually in use. Always write nebiusrelay --main