Skip to content
Last updated

Codex Integration

Use OpenAI Codex — a coding assistant that lives in your terminal — with Treasure AI as the backend.

Treasure AI customers can use Codex with their existing AI Suite credits — no separate OpenAI subscription required for TD-routed traffic.

Experimental

tdx codex is an experimental integration. Behavior, flags, and defaults may change in future releases as the Codex CLI itself evolves.

Why use it

  • Code faster with AI in your terminal. Ask questions, refactor code, generate tests, or write new features — all in plain English, right where you already work.
  • One subscription for everything. Reuse your Treasure AI account and AI Suite credits instead of paying for a separate OpenAI plan. Usage rolls up under your TD account, so billing and access control stay in one place.
  • Keeps your existing Codex setup intact. If you already use Codex against OpenAI, that config is left completely alone. tdx codex only wires up the Treasure AI provider for the session it launches.
  • Automatic sign-in. Codex re-uses your tdx login, so you don't manage a second set of API keys and tokens don't expire mid-session.
  • TD skills included. Codex gets the tdx skills for segments, journeys, workflows, and the rest of the tdx CLI automatically.
  • Works with your active profile. Multi-account or multi-region users get routed to the right place based on the tdx profile they've selected.

What it helps with

Once you launch Codex in a tdx-managed project, you can ask it to help with the tasks tdx is built for:

  • Marketing as code — draft and edit YAML definitions for parent segments, audiences, journeys, and campaigns, then have Codex run tdx pull/push/validate for you.
  • Write SQL against your TD data — ask for a Trino query over your databases and tables, refine it in the terminal, and paste it into tdx query.
  • Author workflows — draft .dig workflow files that ingest data, transform tables, or trigger jobs on a schedule.
  • Define CDP journeys and audiences — describe the audience or realtime journey you want, and have Codex produce (or edit) the YAML that tdx will apply.
  • Explore and evolve an existing TD project — explain unfamiliar YAML, SQL, or workflow files, refactor them, add validation tests, and generate boilerplate for new segments or connections.

It also works for anything Codex is normally good at — reading unfamiliar code, refactoring, generating tests, debugging errors, and writing small scripts.

Quick start

You'll need a Treasure AI account with AI Suite access.

# 1. Install Codex (once per machine)
curl -fsSL https://chatgpt.com/codex/install.sh | sh

# 2. Sign in to tdx (once per profile)
tdx auth setup

# 3. Launch Codex against Treasure AI
tdx codex

Prefer a different Codex installer? brew install --cask codex (macOS) and npm install -g @openai/codex (any platform) also work — see the Codex CLI docs for options.

Examples

# Just launch Codex
tdx codex

# Start Codex with an initial prompt
tdx codex -- "Explain this code"

# Use a specific tdx profile — its region is used automatically
tdx --profile production codex

# Pick a model or pass any other Codex flag through
tdx codex -- --model gpt-5.5 "hello"

Anything after -- is passed to Codex unchanged, so any option supported by the Codex CLI is available.

Default model

For TD internal users (signed-in email at treasure.ai or treasure-data.com), tdx codex defaults to auto when no --model (or -m) option is supplied. This session-only argument takes precedence over Codex's configured default; pass --model <model> to choose another model. No persistent configuration is changed.

Resumed sessions (resume subcommand) keep the model they were started with. External users keep Codex's own model selection. If tdx cannot determine the signed-in user's email, it leaves the model unchanged.

Example prompts

Once you're inside a Codex session, you can ask things like:

> Add a workflow to periodically import data from S3 into mydb.orders

> Write a SQL query to find the top customers by revenue in the last 30 days

> Create a parent segment YAML for customers who purchased in the last 60 days

> Add an audience under this parent segment for high-value customers with an email opt-in

> Explain what this journey definition does, and add a stage for a re-engagement email

> Refactor this workflow so the S3 import runs hourly instead of daily

Options

tdx codex accepts the standard tdx global options — most usefully --profile <name> to pick which account and region to route through, and --verbose to print the exact Codex command that gets launched. Everything after -- is passed to Codex unchanged.

TD skills

tdx codex installs the tdx skills — tdx-basic, segment, journey, and the rest — so Codex knows how to work with tdx and Treasure AI out of the box. Nothing to set up.

  • Skills are placed in ~/.agents/skills, the folder Codex reads personal skills from. They are copies of the skills bundled with your installed tdx, the same ones tdx claude installs, so they match the commands in your tdx version. Run tdx skill list --installed --global to see them.
  • They update when you upgrade tdx; no download is needed. TDX_TD_SKILLS_REPO and the former two-week refresh no longer apply to Codex skills. A skill you delete from ~/.agents/skills comes back on the next launch.
  • Links created by older tdx codex versions are migrated from the cached td-skills checkout to the bundle. The old checkout is left on disk. tdx records its managed link targets in ~/.cache/tdx/codex_skills.json so they can be repaired if an upgrade moves the install path.
  • If you already have a skill with the same folder name, yours is kept and tdx codex prints a warning instead of replacing it.
  • If the skills can't be installed, tdx codex prints a warning and Codex still launches. Concurrent setups are protected by ~/.cache/tdx/codex_skills.json.lock. If setup is forcibly terminated, a leftover lock may need manual removal after confirming no other setup is running.

Other tools that read ~/.agents/skills see these skills too. To remove them, delete the links from ~/.agents/skills and stop launching with tdx codex.

Usage report

tdx usage
tdx usage --json

The report shows usage by profile and source across the shared tdx usage ledger. While tdx codex is running, it records new token events from Codex's rollout logs for the td provider in the current workspace, then flushes pending events when Codex exits. Resuming a session does not import its old history. Sessions that disable rollout persistence cannot be recorded.

Prices come from the account's /v1/work/models catalog, including cache and long-context rates. Catalogs refresh periodically and retain their last successful response for offline use. Models without catalog prices use bundled estimates. Amounts use current prices and are estimates, not historical invoices.

Production account 1

tdx codex is not available on production account 1 (TD account ID 1 on a non-dev, non-staging site). Interactive Codex saves full session rollouts locally, and history.persistence = "none" only disables prompt history. Use tdx claude, which turns off local conversation history for that account. tdx opencode is blocked for the same reason.

Client identification

TD LLM requests use X-TD-Client: tdx/codex through session-scoped provider headers. TD API requests made by child tdx commands inherit the same identity through TDX_CLIENT. The User-Agent retains tdx/<version> and adds client=tdx/codex in its comment; X-TD-Client-Version remains the tdx version. Ordinary CLI requests remain identified as tdx.

Parent startup requests and OAuth token refresh requests are outside this attribution. Forwarded Codex configuration overrides can replace the injected provider headers; no persistent Codex configuration is changed.

Troubleshooting

Codex says it can't find the tdx command. Make sure tdx is installed globally and on your PATH (e.g. npm install -g @treasuredata/tdx), then rerun tdx codex.

Codex authentication fails after tdx codex starts. Check your sign-in with tdx status — it shows whether the active profile is authenticated. If not, run tdx auth setup to sign in again, then relaunch Codex.

Codex seems to be using the wrong account or region. The active profile is captured when Codex launches, so switching profiles in another shell doesn't retarget an already-running Codex. Quit Codex and relaunch it with the profile you want: tdx --profile <name> codex.

Learn More