Reduce AI Coding Costs: Run Open-Source Models in Codex with Ollama
A practical guide to replacing paid API models in the Codex AI coding tool with free, open-source alternatives using Ollama.
Practical Summary
This guide shows developers how to configure the Codex App, CLI, and SDK to use open-source models like GLM-5.2 and Kimi-K2.7-Code via Ollama, eliminating the need for a paid OpenAI API key for coding assistance tasks.
Why It Matters
For developers and teams, this method can significantly reduce AI tool costs. Instead of paying per-token API fees to OpenAI or others, you can run capable open-source models locally or on your own infrastructure, converting a variable operational expense into a fixed, potentially lower, cost.
Step 1: Install Ollama
First, ensure you have Ollama installed on your system. Ollama is an open-source tool for running large language models locally. Download and install it from the official Ollama website (https://ollama.com).
Step 2: Pull the Desired Open-Source Model
Once Ollama is installed, open your terminal or command prompt. Use the `ollama pull` command to download the model you want to use. For example, to get the models mentioned in the source, run: `ollama pull glm-5.2` or `ollama pull kimi-k2.7-code` This downloads the model files to your local machine.
Step 3: Launch Codex with Ollama
With the model downloaded, you can launch the Codex integration. The source provides two example commands: 1. To use the core Codex CLI integration, run: `ollama launch codex` 2. To launch the Codex App interface, run: `ollama launch codex-app` These commands should configure Codex to use your local Ollama model instead of remote OpenAI APIs.
Step 4: Use Codex for AI-Assisted Coding
After launching, you can use the Codex App or CLI as you normally would. Your code suggestions, completions, and chat interactions will now be powered by the open-source model running locally via Ollama. This workflow allows you to leverage AI coding assistance without incurring API costs.