Back to Tensorzero

Example: Integrating OpenAI Codex with TensorZero

examples/integrations/openai-codex/README.md

2026.4.14.4 KB
Original Source

Example: Integrating OpenAI Codex with TensorZero

This example shows how to use OpenAI Codex with TensorZero — fully open-source and self-hosted.

Why?

Getting Started

Prerequisites

  1. Install Docker.
  2. Install Node 24.13.0.
  3. Generate credentials for the providers you want to use (e.g. ANTHROPIC_API_KEY).

Setup

  1. Create a .env file with your provider credentials. (See .env.example for reference.)

  2. Run docker compose up to start TensorZero.

  3. Install Codex: npm i -g @openai/codex

  4. Add the TensorZero Gateway to your Codex configuration (~/.config/config.yaml or ~/.codex/config.json):

    yaml
    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 ...
    
    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"
        }
      }
    }
    
  5. Run Codex with TensorZero:

    bash
    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 recipes, and more. See our Quick Start Guide for more details.

<p align="center"> <em>OpenAI Codex Observability with the TensorZero UI</em> &mdash; <code>http://localhost:4000/</code></p>