Use OpenAI Codex CLI with Datagram

Run OpenAI's open-source Codex coding agent on Qwen3-Coder hosted on our own Apple Silicon, with its file-editing tool working natively. One small config file.

Works with Datagram AI

All guides · API quickstart · Last checked: Codex CLI 0.172.0, November 2026: reading, running commands and editing files (apply_patch) tested end to end against our live API

  1. 1. Create an accountSign up in a minute and get $5 of free credit. Already a customer? Sign in.
  2. 2. Make an API keyIn your account, open AI API and press Create key. Keys start with dgk_. Keep yours secret.
  3. 3. Follow the steps belowCopy each block, paste your key where it says dgk_your_key_here.

1. Install Codex

npm install -g @openai/codex

Or brew install codex on a Mac. You don't need an OpenAI account.

2. Point it at Datagram

Put this in ~/.codex/config.toml (create the file if it isn't there):

model = "qwen3-coder:30b-64k"
model_provider = "datagram"

[model_providers.datagram]
name = "Datagram"
base_url = "https://api.datagram.net/v1"
env_key = "DATAGRAM_API_KEY"
wire_api = "responses"
model_catalog_url = "https://api.datagram.net/v1/codex/models.json"

Then put your key in your shell profile (~/.zshrc or ~/.bashrc):

export DATAGRAM_API_KEY=dgk_your_key_here

3. Try it

Open a terminal in a project folder and run codex, or try a one-off task:

codex exec "Find and fix the bug in calc.py"

In our test Codex read the file, explained the bug and fixed it with a patch in a few seconds. It asks before running commands or changing files unless you choose otherwise (see codex --help for --sandbox and approval options).

If something goes wrong

"Model metadata for qwen3-coder:30b-64k not found"

The model_catalog_url line is missing or mistyped. It must be inside the [model_providers.datagram] section and on the same address as base_url.

It asks me to sign in to ChatGPT or OpenAI

Check model_provider = "datagram" is at the top of the file (not inside a section) and that DATAGRAM_API_KEY is set in the terminal you run Codex from (echo $DATAGRAM_API_KEY).

401 "Invalid or revoked API key"

Copy the key again from your account under AI API; it starts with dgk_.

A patch fails and Codex retries

That's normal now and then: Codex checks every patch before applying it and the model corrects itself. If a big change keeps failing, ask Codex to make it in smaller steps.

402 "credit has run out"

Add credit in your account under AI API. Credit never expires.

Questions

Does this use OpenAI's models?

No. Codex is the tool; the model answering is Qwen3-Coder 30B on our hardware. It handles everyday coding tasks well; for the hardest problems OpenAI's largest models are stronger.

Why qwen3-coder:30b-64k?

Codex sends long instructions and tool descriptions with every step. This model has a 65,536-token window; our others have 8,192, which is too small for Codex.

What does model_catalog_url do?

It tells Codex about our model: its window size, when to compact the conversation, and that it can use Codex's apply_patch file-editing tool. Without it Codex warns that it doesn't know the model and edits files through the shell instead.

What does it cost?

The normal token price of qwen3-coder:30b-64k from your Datagram credit. Repeated input (Codex resends the conversation each step) is cached and costs a tenth. A small bug fix used about 10,000 tokens in our test: a fraction of a cent.

Is my code private?

Yes. Requests go to our own Macs and we never store prompts or answers, only counts for billing. Codex itself runs on your computer.

Create an account Get an API key More guides →