Slash Your AI Coding Costs: Connect Codex with Chinese Large Models in 10 Minutes

This guide shows how the high OpenAI Codex fees can be replaced by domestic large language models—DeepSeek, GLM‑4.7, Qwen3.5 and others—through three practical integration methods, providing step‑by‑step commands, configuration files, performance benchmarks and cost‑saving calculations for individual developers and teams.

Old Meng AI Explorer
Old Meng AI Explorer
Old Meng AI Explorer
Slash Your AI Coding Costs: Connect Codex with Chinese Large Models in 10 Minutes

Why Use Domestic Models? It’s Not Just About Money

OpenAI’s pricing can reach $50‑$200 per month for heavy Codex users, while Chinese models such as DeepSeek V3.2, GLM‑4.7 and Qwen3.5 offer comparable or better code‑generation capabilities at 1/10‑1/50 of the cost.

Cost Comparison (Illustrative)

GPT‑5.4: $15 input, $60 output per million tokens (baseline).

Claude Opus 4.6: $12 input, $45 output (baseline).

DeepSeek V3.2: $0.27 input, $1.10 output – 1/55 of baseline.

GLM‑4.7: $0.80 input, $3.20 output – 1/18 of baseline.

Qwen3.5‑Plus: $0.08 input, $0.32 output – 1/187 of baseline.

For a medium team processing 500 k tokens per month, the monthly cost drops from about $600 (GPT‑5.4) to $11 with DeepSeek, saving over $7 000 per year.

Three Practical Integration Solutions

Solution 1: Ollama Launch – Zero‑Config (Recommended)

This is the simplest method. Ollama’s launch command automatically configures the environment and supports both local and cloud models.

One command installs and runs the model.

Supports automatic 64 K context length.

# Check Ollama version
ollama --version
# If version <0.15, download the latest from ollama.com

Pull a model (cloud example):

ollama pull glm-4.7:cloud
ollama pull deepseek-v3.2:cloud
ollama pull qwen3-coder:480b-cloud

Start Codex with the chosen model:

# Interactive selection
ollama launch codex
# Direct model selection
ollama launch codex --model glm-4.7:cloud

Solution 2: Manual Configuration – Full Control

Suitable for enterprise environments where you need to edit configuration files directly.

Obtain API keys from the provider’s portal (e.g., https://open.bigmodel.cn/ for GLM‑4.7, https://platform.deepseek.com/ for DeepSeek, https://dashscope.aliyun.com/ for Qwen).

Edit the Codex config file ( ~/.codex/config.toml on macOS/Linux or %USERPROFILE%\.codex\config.toml on Windows) to specify the model provider, base URL and API key.

# GLM‑4.7 example
model_provider = "bigmodel"
model = "glm-4.7"

[model_providers.bigmodel]
name = "Zhipu AI"
base_url = "https://open.bigmodel.cn/api/paas/v4"
api_key = "YOUR_GL M_API_KEY"
# DeepSeek V3.2 example
model_provider = "deepseek"
model = "deepseek-chat"

[model_providers.deepseek]
name = "DeepSeek"
base_url = "https://api.deepseek.com/v1"
api_key = "YOUR_DEEPSEEK_API_KEY"
# Qwen3.5 example
model_provider = "qwen"
model = "qwen-max"

[model_providers.qwen]
name = "Alibaba Cloud"
base_url = "https://dashscope.aliyuncs.com/compatible-mode/v1"
api_key = "YOUR_QWEN_API_KEY"

Create an auth.json file in ~/.codex/ containing the API key:

{
  "OPENAI_API_KEY": "YOUR_DOMESTIC_MODEL_API_KEY"
}

Restart Codex to apply the changes.

Solution 3: VSCode Plugin – Visual Management

Install the official Codex extension from the VSCode Marketplace, then configure the custom model via the Settings UI or by editing the JSON configuration.

Open VSCode.

Press Ctrl+Shift+X (or Cmd+Shift+X on macOS) and search for “Codex”.

Install the extension.

Navigate to Settings → Model Settings, choose “Custom”, and fill in the provider URL and API key.

Alternatively, edit the user settings JSON:

{
  "codex.config": {
    "modelProvider": "bigmodel",
    "model": "glm-4.7",
    "apiEndpoint": "https://open.bigmodel.cn/api/paas/v4",
    "apiKey": "YOUR_API_KEY"
  }
}

Performance Benchmarks (2026)

Code‑generation speed: GPT‑5.4 = 83 tokens/s, GLM‑4.7 = 56 tokens/s, MiniMax M2.5 = 58 tokens/s.

HumanEval pass rate: DeepSeek V3.2 = 94 %, GPT‑5.4 = 91 %, Claude Opus 4.6 = 89 %.

AIME math reasoning: Qwen3.5‑Max = 87.5 %, DeepSeek V3.2 = 87.5 %.

Frequently Asked Questions

Codex shows no response after configuration

Verify the API key with a curl test.

curl -X POST https://open.bigmodel.cn/api/paas/v4/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"glm-4.7","messages":[{"role":"user","content":"test"}]}'

Check network connectivity (e.g., ping open.bigmodel.cn).

Inspect Codex logs with codex --debug.

Context window “forgetting” issue

Switch to a model with long context (e.g., Kimi K2.5 with 256 K).

Periodically run /compact to compress conversation history.

Use Ollama Launch, which automatically sets a 64 K context.

Generated code quality is lower than GPT‑5.4

Provide clearer file context using Codex’s file‑attachment feature.

Break complex tasks into smaller steps.

Encode team coding standards as a Skill (see below).

Experiment with different models—GLM‑4.7 or DeepSeek often outperform GPT‑5.4 on code tasks.

Advanced Feature: Skills

Skills let you embed reusable workflows. Example: a “Team Code Review Expert” that enforces naming conventions, error handling, performance checks, and security rules.

---
name: "Team Code Review Expert"
description: "Enforce team coding standards"
version: "1.0"
tags: ["code-review", "quality", "standards"]
---
You are a senior code reviewer. Follow these rules:
## Review Checklist
### 1. Code Style
- [ ] Follow ESLint/Prettier config
- [ ] CamelCase for variables, UPPER_CASE for constants
- [ ] Functions < 50 lines
- [ ] Comments cover at least 30% of code
### 2. Error Handling
- [ ] All async calls wrapped in try‑catch
- [ ] API calls have retry logic
- [ ] Edge cases handled
### 3. Performance
- [ ] No unnecessary renders (React)
- [ ] Use pagination or virtual scroll for large data
- [ ] Avoid expensive ops inside loops
### 4. Security
- [ ] Validate and escape user input
- [ ] No sensitive data exposed in front‑end
- [ ] Dependencies have no known vulnerabilities
## Output (JSON)
```json
{
  "passed": true,
  "issues": [],
  "summary": "All checks passed"
}
```

Save the skill under ~/.codex/skills/code-reviewer and invoke it with:

# Natural language trigger
Use the "Team Code Review Expert" skill to review the current file.
# Explicit command
codex run --skill code-reviewer --file src/components/UserList.tsx

Best Practices for Maximizing Domestic Model Value

Model selection strategy : simple CRUD → Qwen3.5‑Plus; daily development → GLM‑4.7; heavy algorithmic work → DeepSeek V3.2; long‑term projects → Kimi K2.5.

Context management : run /compact regularly, attach files instead of copy‑pasting, use Skills to avoid repetitive prompts.

Skill accumulation : create reusable Skills for commit messages, PR descriptions, API docs, code‑review checks, unit‑test generation.

Cost monitoring : use /cost and /stats commands; set warning thresholds via /config → set cost_warning_threshold 10.

Security : never commit API keys, store them in environment variables, enable Codex sandbox mode, regularly audit generated code.

Future Outlook (2026)

Domestic models are expected to further cut prices by up to 50%, become runnable on ordinary laptops (20 B parameters or less), add multimodal capabilities, and spawn industry‑specific variants for finance, healthcare and education. By the end of 2026, they should capture over 60 % of the code‑generation market in China.

Quick Reference

One‑Click Ollama Launch Command

# Install Ollama (download from ollama.com)
# Pull a cloud model
ollama pull glm-4.7:cloud
# Launch Codex with the model
ollama launch codex --model glm-4.7:cloud

Common Commands

/config

– view current configuration. /cost – display current usage cost. /compact "keep current implementation idea" – compress conversation. /model – switch model. /skills – list available Skills. /status – show Codex status.

Domestic Model API Endpoints

Zhipu AI – https://open.bigmodel.cn/api/paas/v4 (recommended: GLM‑4.7).

DeepSeek – https://api.deepseek.com/v1 (recommended: DeepSeek V3.2).

Alibaba Cloud – https://dashscope.aliyuncs.com/compatible-mode/v1 (recommended: Qwen3.5‑Plus).

Moonshot – https://api.moonshot.cn/v1 (recommended: Kimi K2.5).

Speed‑Optimization Tips

Use Ollama Launch for automatic 64 K context.

Prefer cloud models to avoid hardware bottlenecks.

Compress context regularly with /compact.

Leverage Skills to reduce repeated prompts.

Don’t wait for a perfect moment—domestic models already match or exceed OpenAI’s performance at a fraction of the cost. A ten‑minute setup can save thousands of dollars each year.

AI codinglarge language modelscost optimizationmodel selectionOllamaCodex integration
Old Meng AI Explorer
Written by

Old Meng AI Explorer

Tracking global AI developments 24/7, focusing on large model iterations, commercial applications, and tech ethics. We break down hardcore technology into plain language, providing fresh news, in-depth analysis, and practical insights for professionals and enthusiasts.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.