Example: Integrating OpenAI Codex with TensorZero
This example shows how to use OpenAI Codex with TensorZero — fully open-source and self-hosted.
Why?
- Use every major model provider with Codex: Anthropic, AWS Bedrock, AWS SageMaker, Azure, DeepSeek, Fireworks, GCP Vertex AI Anthropic, GCP Vertex AI Gemini, Google AI Studio (Gemini API), Hyperbolic, Mistral, OpenAI, Together, vLLM, xAI, and any OpenAI-compatible provider (e.g. Ollama)
- Gain comprehensive observability into your Codex usage, including detailed logs for every LLM call.
- Set up advanced inference features like retries, fallbacks, load balancing, inference-time optimizations, experimentation (A/B testing), and more.
- Collect data for fine-tuning and other optimization techniques, and use TensorZero optimization workflows to create custom models for your Codex usage.
Getting Started
Prerequisites
- Install Docker.
- Install Node 24.13.0.
- Generate credentials for the providers you want to use (e.g.
ANTHROPIC_API_KEY).
Setup
-
Create a
.envfile with your provider credentials. (See.env.examplefor reference.) -
Run
docker compose upto start TensorZero. -
Install Codex:
npm i -g @openai/codex -
Add the TensorZero Gateway to your Codex configuration (
~/.config/config.yamlor~/.codex/config.json):model: "tensorzero::model_name::anthropic::claude-sonnet-4-5-20250929" provider: tensorzero providers: tensorzero: name: TensorZero baseURL: http://localhost:3000/openai/v1 envKey: TENSORZERO_API_KEY # not used but required by Codex # ... other providers ...{ "model": "tensorzero::model_name::anthropic::claude-sonnet-4-5-20250929", "provider": "tensorzero", "providers": { "tensorzero": { "name": "TensorZero", "baseURL": "http://localhost:3000/openai/v1", "envKey": "TENSORZERO_API_KEY" } } } -
Run Codex with TensorZero:
TENSORZERO_API_KEY="not-used" codex # or set the environment variable in your shell and just run `codex`
You can replace tensorzero::model_name::anthropic::claude-sonnet-4-5-20250929 with any other model supported by TensorZero, e.g. tensorzero::model_name::mistral::open-mistral-nemo-2407.
You can also define custom TensorZero functions in the config/tensorzero.toml file, and use them with Codex as tensorzero::function_name::your_function_name.
This will enable you to use advanced inference features, collect data for fine-tuning and other optimization workflows, and more.
See our Quick Start Guide for more details.
OpenAI Codex Observability with the TensorZero UI — http://localhost:4000/