DEV Community

Adela for BetterToken.ai

Posted on Originally published at bettertoken.ai

Claude Code and Codex APIs: Protocol, Configuration, and First-Test Checks

Claude Code and Codex APIs: Protocol, Configuration, and First-Test Checks

Short answer: an OpenAI-compatible label does not make one setup work for both tools. Claude Code uses the Anthropic Messages contract; Codex custom providers use the OpenAI Responses contract. Verify the tool-specific guide, Base URL, authentication field, and current Model ID before you compare a price or send a repository task.

If you want to test both paths through BetterToken, start with its current Claude Code setup guide and Codex setup guide. They use separate protocol-specific endpoints and a key you create in your own account. Run one short request first, then use Dashboard to inspect its status, model, input/output/cache tokens, and charge.

The two client contracts are different

Client What its configuration must establish BetterToken path to verify
Claude Code Anthropic-compatible Messages access, plus the documented authentication variables Base URL: https://bettertoken.ai; Claude Code appends /v1/messages
Codex CLI/App A custom provider that uses Responses, not just Chat Completions Base URL: https://www.bettertoken.ai/v1; wire_api = "responses"

For Claude Code, BetterToken's current guide uses ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN. Do not add /v1 to that Base URL: the client adds the Messages path itself. For Codex, the provider lives in ~/.codex/config.toml; its key is read from BETTERTOKEN_API_KEY, and the provider needs requires_openai_auth = false when you are using the custom-provider path.

These are not interchangeable settings. A URL that works for a Responses request does not prove that it will serve Claude Code. Conversely, an Anthropic-compatible route is not evidence that Codex can use it. The OpenAI Codex configuration reference and the Claude Code documentation are the primary references for the clients; use your provider's current guide for its values.

A minimal configuration check

For Codex, confirm the provider table follows the documented Responses pattern before launching the client:

model_provider = "custom"
model = "YOUR_MODEL_ID"

[model_providers.custom]
base_url = "https://www.bettertoken.ai/v1"
env_key = "BETTERTOKEN_API_KEY"
wire_api = "responses"
requires_openai_auth = false
Enter fullscreen mode Exit fullscreen mode

YOUR_MODEL_ID is deliberately a placeholder. Model availability and exact IDs are dynamic, so copy a complete current ID from the provider's setup dialog or model catalog rather than an old article. Do not put a custom-provider key in ~/.codex/auth.json.

For Claude Code, verify the two protocol settings instead of trying to reuse the Codex table:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://bettertoken.ai",
    "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY"
  }
}
Enter fullscreen mode Exit fullscreen mode

The exact file location and optional variables belong to the current Claude Code guide. Keep secrets out of prompts, issues, screenshots, and repositories.

Test before a real workload

  1. Open the current guide for the exact client and version you will run.
  2. Create your own test API Key; do not use a shared account or paste the key into project files.
  3. Copy the provider's Base URL and current Model ID from its current documentation or dashboard.
  4. For Claude Code, confirm the Anthropic-compatible route and credential variables. For Codex, confirm wire_api = "responses", the provider name, and the environment variable.
  5. Start in an empty or disposable repository with no production secrets.
  6. Send a small, bounded task and confirm that the client returns normally rather than only accepting the configuration file.
  7. In the provider dashboard, record the request status, resolved model, input/output/cache tokens, retry count if shown, and final charge. Then repeat one representative task under the same conditions before choosing a provider.

This order makes the first request a diagnostic, not a blind migration. It also prevents a misleading comparison in which a bad route, an old model ID, and a pricing difference are mixed together.

Compare cost without false precision

The input-token price alone is rarely the cost of an agent task. Context files, conversation history, tool output, cached tokens, retries, and output length can all change the final bill. For each candidate, log the exact Model ID, input/output/cache tokens, request count, errors or retries, any applicable funding fee, and the charge for one identical task.

Use BetterToken's current pricing page for its live model and price data. Treat any numbers in a dated review as historical. The same rule applies to another provider's catalog, limits, funding methods, and fee terms.

First-request errors: what to check

Symptom First check
401 or an authentication error The key belongs to this provider, the documented field is used, and there are no pasted spaces
404 or connection failure The client has the documented Base URL for its protocol; do not add a full request path where the client appends one
model not found The Model ID is complete and copied from the current catalog for the same provider and key group
Codex API-mode error wire_api = "responses" is present; a Chat Completions-only setup is not enough
429 The endpoint's limit, Retry-After, and whether that request is safe to retry
Streaming stops Protocol-specific streaming support, the network, and the dashboard status for that request
An unclear charge Model, input/output/cache token records, and retries in usage history

Change one variable at a time and rerun the short task. Replacing the URL, key, model, and client configuration together removes the evidence needed to find the cause.

Make the decision from a recorded test

Do not turn this checklist into a speed, stability, or lowest-price ranking. It is a way to verify two distinct client contracts. Confirm current documentation on the day of your test, run one repository task with the same model intent and scope, and decide from the configuration result, errors, token record, and final charge.

For BetterToken, open the Claude Code guide or Codex guide, create a separate API Key in your account, and verify the first request in Dashboard before moving production work.


Originally published on the BetterToken blog.

BetterToken provides pay-as-you-go access to AI model APIs through
OpenAI-compatible and Anthropic-compatible endpoints — useful if you are wiring
Claude Code, Codex, or your own tooling to a custom base URL.
See the docs to get started.

Top comments (0)