页面简介
Use open models with OpenAI Codex on your device locally.
正文摘录
This step-by-step guide shows you how to connect open LLMs and APIs to OpenAI Codex entirely locally, complete with screenshots. Codex only needs a local endpoint that speaks the OpenAI Responses API. Run using any open model like Qwen, DeepSeek, Gemma, and more.For this tutorial, we’ll use the open models: Gemma 4 and Qwen3.5 which are strong agentic & coding models (works on 24GB RAM/unified mem device). For inference, we'll use Unsloth Studio and llama.cpp enables you to run/serve LLMs on macOS, Linux, and Windows. You can swap in any other model, just update the model names in your scripts and Codex config.Setup Codex📖 Setup Local Model TutorialFor model quants, we'll use Unsloth Dynamic GGUFs so you can run quantized GGUF models while retaining as much accuracy as possible.Codex has changed quite a lot since Jan 2026. It now uses the OpenAI Responses API exclusively, and Chat Completions support has been deprecated. Unsloth Studio supports both, so we'll use wire_api = "responses" throughout this guide. Setup CodexCodex is OpenAI's official coding agent that runs locally. While designed for ChatGPT, it supports custom API endpoints, which makes it work for local LLMs. We'll later point it to Unsloth Studio's /v1/responses endpoint once Unsloth is up.Linux / WSLWindowsMacOSRun in your terminal:AskCopyapt update sudo apt install nodejs npm -y npm install -g @openai/codexRun in Windows Powershel:AskCopywinget install --id OpenAI.CodexPrefer the Codex desktop app? Install from the Microsoft Store:AskCopywinget install --id 9PLM9XGG6VKS --source msstoreOr via the Microsoft app Store. The app reads the same %USERPROFILE%\.codex\config.toml, so the provider config we set up later applies either way.Prefer WSL? Open PowerShell as admin, run wsl --install, restart, then follow the Linux tab above inside Ubuntu. You'll need a small networking trick to reach Unsloth on the Windows host - see the WSL hint in Connect Codex to Unsloth.Run in your terminal:AskCopybash brew install --cask codexThat's it for the install - don't run codex yet. Running it bare drops you into OpenAI's "Sign in with ChatGPT" picker (which is modal - there's no escape hatch). Once we wire up a local profile, codex --oss --profile unsloth_api or codex --oss --profile llama_cpp skips that screen entirely because custom providers default to requires_openai_auth = false. Start the local model server first, then launch Codex against it.📖 Quickstart TutorialsBefore we begin, we firstly need to complete setup for the specific model you're going to use. We use Unsloth (a web UI) and llama.cpp which are open-source frameworks for running and serving LLMs on your Mac, Linux, Windows devices.Before we begin, we firstly need to complete setup for the specific model you're going to use. We use Unsloth (a web UI) and llama.cpp which are open-source frameworks for running and serving LLMs on your Mac, Linux, Windows devices.Unsloth also has unique self-healing tool-calling and web search capabilities. See right for Claude Code connected to Unsloth:🦥 Unsloth Tutorial🦙 llama.cpp Tutorial🦥 Unsloth TutorialFor this tutorial, we will serve/connect local models to Claude Code via a UI by using Unsloth. Unsloth works on Windows, WSL, Linux and MacOS.Search, download, run GGUFs and safetensor modelsSelf-healing tool calling + web searchCode execution (Python, Bash)Automatic inference parameter tuning (temp, top-p, etc.)Fast CPU + GPU inference via llama.cppTrain LLMs 2x faster with 70% less VRAMSee below for install instructions:Example of Qwen3.6 2-bit running in Unsloth.1Download UnslothThe easiest way to get started is by installing the Unsloth Desktop app. It supports MacOS, Linux, Windows, NVIDIA, AMD, Intel and CPU setups.Download Unsloth Download for macOS Download for Windows Download for LinuxOr, if you prefer manual installation:MacOS, Linux, WSL:Windows PowerShell:2InstallOpen the Unsloth installer (.dmg, .exe files)Drag Unsloth to Applications for Mac or complete setup for Windows.Launch the app and wait for installation to complete3Choose a modelOpen 'Select model' dropdown ontop or 'Model hub' tab, choose a model and a quantization that fits your device, then download it. Once it finishes, start chatting - no setup required.4Unsloth is now readyTo start chatting, type a message and press Enter.Connect tools: Claude Code, Codex, web search, MCP and moreTrain models: Fine-tune text, diffusion, embedding, and moreGenerate media: Create and train images, video, TTS locallyModel Loading + API Guide1Select ModelBefore using the API, load a model from the Select model dropdown in the top-left corner of the Chat page.In this guide, we’ll use: unsloth/gemma-4-26B-A4B-it-GGUF with the recommended UD-Q4_K_XL quantization.2Test the ModelBefore using the Client, send a quick message:This confirms that the model loaded correctly and is ready to respond.3Unsloth API keyIn Unsloth, open Settings → API to view or create your API key. If you start Unsloth headless with unsloth run, the key is also printed to the console as sk-unsloth-....Treat your API key like a password and avoid exposing it in screenshots or repositories.Optional: adjust runtime settingsYou can pass additional runtime options when starting a model with unsloth run.Reasoning-capable models can be started with --reasoning on or --reasoning off. The -c flag controls the available context window.Use -p if you need the API to run on a different port.When driving an external coding agent, add --disable-tools. This switches Unsloth Studio to passthrough so the agent's own tools are forwarded and returned as tool calls for the agent to run, instead of Unsloth executing its built-in tools server-side.For more advanced runtime configuration, see the main API tuning section.⚙️ Connect CodexNow that we have setup the local LLM for Codex, we now configure Codex to work with your tool. You can either connect easily with unsloth start below or do it manually.⚡ Run OpenAI Codex with unsloth startTo launch Codex directly with a model, run:If there are no settings/sampling flags set, Unsloth automatically selects the best/recommended settings for the model including context length, temperature etc.With a GGUF model loaded in Unsloth Studio, open your project folder and run:Unsloth creates an isolated Codex home and a Unsloth backed Responses provider for the launch. Your normal ~/.codex configuration is left alone.Codex state is temporary by default. Use --persist when you want to keep its Unsloth-managed configuration and sessions:Codex connected to a local GGUF model through the Unsloth Studio Responses endpoint.Codex currently requires a GGUF model served through the llama-server backend.See the complete unsloth start reference for model loading, persistence and all wrapper options.The rest of this guide covers a fully manual Codex provider setup.🔌 Connect manuallyThis section is for manual setting up, it is the same whether you used Unsloth Studio, llama.cpp, or another OpenAI-compatible local server. Codex needs three values: the API key, the base URL, and the model name. The example below uses Unsloth Studio; for llama.cpp, use the same shape with the llama_cpp profile in the llama.cpp section.1Configure the Unsloth providerCodex looks for ~/.codex/config.toml on macOS/Linux/WSL or %USERPROFILE%\.codex\config.toml on Windows. Create or edit it:Next, create a Codex profile for Unsloth:model must match the id your server reports at GET http://localhost:8888/v1/models. Unsloth Studio exposes the full repo id (for example unsloth/gemma-4-26B-A4B-it-GGUF). The llama.cpp section below uses --alias "unsloth/gemma-4-26B-A4B", so use that shorter id when pointing Codex at llama-server instead.This config registers an unsloth_api Codex model provider, points it at Unsloth Studio, and sets unsloth_api as the default local provider for codex --oss. The separate unsloth_api profile selects the Unsloth provider and model only when you launch Codex with --profile unsloth_api, so your normal Codex setup is not changed. Codex reads the API key from an environment variable named UNSLOTH_STUDIO_AUTH_TOKEN. You'll set the real key in the next step.FieldWhat it doesbase_urlYour local server endpoint + /v1env_keyName of the env var Codex reads your API key from. This is not the key itself.wire_apiresponses. Codex now exclusively uses OpenAI's Responses API.requires_openai_authfalse makes Codex skip the "Sign in with ChatGPT" screen for this provider. Default is already false, but be explicit.modelThe model ID your server exposes. Hit GET <base_url>/models to confirm the exact string.oss_providerSets unsloth_api as the default local provider when launching Codex with --oss.requires_openai_authfalse makes Codex skip the "Sign in with ChatGPT" screen for this provider.OpenAI removed wire_api = "chat" support. Always use wire_api = "responses". If you set wire_api = "chat", Codex refuses to start with `wire_api = "chat"` is no longer supported. How to fix: set `wire_api = "responses"` in your provider config.You can create multiple profile files, one for each Unsloth model you swap between. Launch the one you want with codex --profile <profile-name>.2Set the API key env varUse the same env var name you wrote in env_key. In the Unsloth Studio example above, env_key = "UNSLOTH_STUDIO_AUTH_TOKEN", so set UNSLOTH_STUDIO_AUTH_TOKEN in the same terminal you will run Codex from:If you renamed env_key, rename the variable in the commands too. For example, a llama.cpp profile that uses env_key = "LLAMA_CPP_API_KEY" needs LLAMA_CPP_API_KEY, not UNSLOTH_STUDIO_AUTH_TOKEN.Session vs Persistent: the commands above apply to the current terminal only. To persist:MacOS / Linux / WSL: add the export line to ~/.bashrc (bash) or ~/.zshrc (zsh).Windows: run setx UNSLOTH_STUDIO_AUTH_TOKEN "YOUR_TOKEN" once, or add the $env: line to your PowerShell $PROFILE.Running Codex inside WSL with Unsloth on Windows? WSL is a separate network namespace, so localhost fr