Codex CLI With Z.ai: Compatibility and Setup Checks

Codex CLI works with providers that offer an OpenAI-compatible API. This guide explains how to check provider compatibility, configure the connection, and keep setup decisions in fenbs when you change coding models.

5 min read

Codex CLI supports custom providers through an OpenAI-compatible API configuration. If a provider exposes a chat completions endpoint that matches the OpenAI API shape, Codex CLI can send requests to it by setting the right environment variables or configuration entries. Whether any particular provider works reliably depends on how closely its API matches the expected format and which model features the provider supports.

Switching coding models is less disruptive when your project context lives outside the model. Tools like fenbs keep setup decisions, project rules, and current progress in a shared record any connected assistant can read, so changing providers does not mean re-explaining the project. The Codex CLI on Windows guide covers the base setup before adding a custom provider.

How Codex CLI connects to custom providers

Codex CLI reads provider settings from environment variables and its configuration file. The two key settings are the API base URL and the model name. When both are set, Codex CLI sends requests to the custom URL instead of the default OpenAI endpoint.

Setting a custom provider in the Codex CLI config
# In ~/.codex/config.yaml or via environment variables
OPENAI_BASE_URL=https://api.example.com/v1
OPENAI_API_KEY=your-provider-key
# Then run with the model name your provider uses
codex --model your-model-name "your task"

The provider must support the chat completions endpoint at /v1/chat/completions with the standard request and response shapes. If it supports tool calls (function calling), Codex CLI can use those too. Providers that return responses in a different format will produce parse errors or empty outputs.

Checking provider compatibility

Before configuring Codex CLI to use a new provider, verify compatibility manually. Send a test request to the provider's chat completions endpoint with a simple prompt and confirm the response matches the OpenAI format. The response should include a choices array with a message.content field.

Check the provider's documentation for which model names it accepts and whether it requires specific header formats. Some providers use the standard Authorization: Bearer header; others expect custom headers. Codex CLI uses the standard header, so a provider that requires a different format will need an intermediate proxy.

For Z.ai specifically, check the current API documentation on Z.ai's own site for the base URL, supported models, and any rate limits that apply. Provider details change; the primary source is always the provider's own documentation rather than a third-party summary.

Evaluating a supported configuration

Compatibility is the first bar; usefulness is the second. A provider that responds to basic prompts may still be a poor fit for coding tasks if its model is not strong at code generation, if it has low rate limits that interrupt long tasks, or if it drops tool calls that Codex CLI relies on.

Test the provider with the kinds of tasks you actually run in Codex CLI. A simple refactoring request, a code explanation, and a test-writing task together give a representative picture. Compare the output to your current provider on the same tasks before committing to the switch.

Check what happens at the context limit and under rate limiting. A provider that silently truncates long contexts or returns generic errors rather than standard HTTP status codes will produce confusing behavior in Codex CLI sessions. The Codex CLI commands guide covers the flags available for controlling session behavior.

What to do if a provider is incompatible

If the provider's API does not match the expected format, an intermediate proxy can translate between formats. Several open-source proxies accept OpenAI-format requests and translate them to other provider APIs. This adds a dependency and a potential point of failure, so evaluate whether the provider is worth the extra complexity.

If tool calls are not supported, Codex CLI can still work in a mode that relies only on text generation, but it will be less capable at multi-step tasks. Check the Codex subagents guide for how tool call support affects multi-agent tasks.

How fenbs helps

Keep project context when you switch coding providers

Connect fenbs over MCP from Codex CLI or another supported tool. When you change providers, the project context stays in fenbs: the tasks, the Decisions and rules, the Where we left off. The new provider reads the same record. The switch costs a configuration change, not a re-briefing. See Integrations for the setup guide.

Create a free account

Free for one person · No credit card · Works with Claude, ChatGPT, Cursor and more

Recording setup decisions

Provider configuration decisions are easy to forget and costly to re-derive. Which provider was tested and why it was chosen or rejected. Which model name the provider uses. What rate limit was encountered and how the workflow was adjusted. These are the facts that matter when you revisit the setup or hand it to a colleague.

Record each setup decision as you make it. A note that says "Z.ai base URL is https://api.z.ai/v1, model name is z-coder-7b, tested October 2026, passed code generation and refactoring tasks" is the kind of record that saves an hour of re-testing next time.

How to do this with fenbs

  1. Create a free account. Add a Codex CLI configuration project with the current provider and model settings.
  2. Record each provider you test in Decisions and rules: the base URL, the model name, the test results, and why you chose or rejected it.
  3. When the setup changes, update the record before continuing. A setup decision that stays in chat history does not reach the next session.
  4. Connect Codex CLI to fenbs via MCP from Integrations. Ask it to read the project context at the start of each coding session.
  5. When you switch providers, save progress first. The tasks and project state in fenbs transfer to the new provider automatically.

Questions people ask.

Does Codex CLI work with any OpenAI-compatible provider?

Codex CLI works with providers that implement the OpenAI chat completions API format correctly. Set the OPENAI_BASE_URL environment variable to the provider's endpoint and provide the corresponding API key. Test with a simple request before using the provider for real work.

What should I check before using a new provider with Codex CLI?

Verify that the provider responds to a test request in the standard OpenAI chat completions format. Check whether it supports tool calls, what rate limits apply, and which model names it accepts. Test with the kinds of tasks you actually run before committing to the switch.

What happens if the provider does not support tool calls?

Codex CLI can still work in a text-generation mode, but multi-step tasks that rely on tool calls will be less capable. Check the Codex CLI documentation for the flags that control which features are used, and test the most complex tasks you run to see whether the capability difference matters for your use case.

How do I switch back to the default OpenAI provider?

Remove or unset the OPENAI_BASE_URL environment variable. Codex CLI will use the default OpenAI endpoint. If you set the variable in a configuration file rather than the environment, remove it there instead.

What project context is lost when I switch providers?

Nothing is lost if the project context lives outside the provider. Store project rules, decisions, and progress in an external record like fenbs. The new provider reads the same record through MCP and continues from the same state.

More in Agent harness (for developers)

All Agent harness (for developers) articles

Start with one thing.

Free for one person · No credit card · Works with Claude, ChatGPT, Cursor and more

There is nothing to set up first. Write one line and you’ve started.