Codex CLI custom API Base URL setup for OpenAI-compatible providers

Configure Codex CLI to use a custom OpenAI-compatible API Base URL, API key, and model. Use RutaAPI's endpoint, verify /v1/models, and troubleshoot common setup errors.

Quick answer

For an OpenAI-compatible provider, use https://api.rutaapi.com/v1 as the Base URL, a RutaAPI API key created from the dashboard, and a model enabled in the app pricing page. Verify everything works with GET /v1/models before running Codex CLI tasks.

Codex CLI setup table

FieldWhat to use with Codex CLI
Base URLhttps://api.rutaapi.com/v1
API KeyYour RutaAPI API key
ModelA model enabled in the RutaAPI app pricing/dashboard
Test endpoint/v1/models

What Codex CLI needs

When you configure Codex CLI with a custom OpenAI-compatible API provider, Codex CLI needs three things:

Depending on your Codex CLI version, the exact config field or environment variable name may vary. Verify the current Codex CLI documentation for your installed version before configuring a custom provider.

Codex CLI version caveat Codex CLI UI labels and config behaviour can change by version. Depending on your Codex CLI version, the exact config field name or environment variable may differ. Users should verify the current Codex CLI config format in their installed version before setting up a custom provider.

RutaAPI values for Codex CLI

Base URL: https://api.rutaapi.com/v1

API key: Create one from the RutaAPI dashboard at app.rutaapi.com. Keys are shown only once at creation — copy and store them securely.

Model: Choose a model enabled in the RutaAPI app pricing page. Run GET /v1/models to see which models are available in your account.

Environment variable example

Depending on your Codex CLI version and configuration method, you may use environment variables or a config file. The example below shows the pattern:

Note: Variable names may differ by Codex CLI version. Check your installed version's documentation for the correct field names.

export OPENAI_API_KEY="YOUR_RUTAAPI_KEY"
export OPENAI_BASE_URL="https://api.rutaapi.com/v1"

If your Codex CLI version uses a different variable name, map the same values to the custom OpenAI-compatible Base URL and API key fields.

Test your key before using Codex CLI

Before running any Codex CLI tasks, verify that your API key and Base URL work together:

curl https://api.rutaapi.com/v1/models \
  -H "Authorization: Bearer YOUR_RUTAAPI_KEY"

If the response returns a model list, your Base URL and API key are working. Use one of the returned model IDs in your Codex CLI configuration.

First request example

Once your key is verified, send a chat completions request to confirm end-to-end connectivity:

curl https://api.rutaapi.com/v1/chat/completions \
  -H "Authorization: Bearer YOUR_RUTAAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "YOUR_ENABLED_MODEL_ID",
    "messages": [
      {"role": "user", "content": "Say hello from RutaAPI"}
    ]
  }'

Replace YOUR_ENABLED_MODEL_ID with one of the model IDs from the /v1/models response. Do not hardcode a model name you have not verified.

How to pick a model

Model IDs are returned by the GET /v1/models endpoint. Copy one of the model id values from the response and use it in your Codex CLI config.

Model availability is per-account. If a model ID is not in your /v1/models response, it is not active in your account — add credits or check the app pricing page for enabled models.

Common Codex CLI setup mistakes

ProblemLikely causeFix
401 / invalid API keyWrong key, missing Bearer, expired or disabled keyCreate a new key in RutaAPI and test /v1/models
Wrong Base URLUsed dashboard URL or homepage URL instead of API endpointUse https://api.rutaapi.com/v1
404 / endpoint not foundMissing /v1 in the Base URLAlways include /v1: https://api.rutaapi.com/v1
Model not foundModel ID is not enabled or typed incorrectlyCheck app pricing page for enabled model IDs
429 rate limitToo many concurrent requests or limited routeSlow down requests or choose another enabled route
503 upstream unavailableUpstream route, gateway, or provider temporarily unavailableRetry, switch model route, or check dashboard for status
Environment variable not loadedShell session not restarted after exportRestart the terminal or re-export the variables
Shell session not restartedConfig changes not picked up by Codex CLIRestart Codex CLI or reload the config

Cost and usage tracking

RutaAPI uses prepaid credits. Check the app pricing page for model rates and enabled routes. After test calls, check the usage logs and remaining balance in the dashboard.

View model pricing

Ready to test RutaAPI? Use one OpenAI-compatible base URL, prepaid credits, and API keys from the dashboard.

FAQ

What Base URL should I use with Codex CLI?

For an OpenAI-compatible provider, use https://api.rutaapi.com/v1 as the Base URL. Always include /v1.

Which API key should I use?

Use a RutaAPI API key created from the dashboard at app.rutaapi.com. Keys are shown only once at creation.

What model should I use?

Use a model enabled in the RutaAPI app pricing page. Run GET /v1/models to see available model IDs. Do not guess — copy the exact ID from the response.

How do I test the key before using Codex CLI?

Call GET /v1/models with your Authorization Bearer header. A 200 response with a model list means the key and Base URL are working.

Why does Codex CLI say model not found?

The model ID may be unavailable, disabled, or typed incorrectly. Check your enabled models in the app pricing page and verify with /v1/models.

Why does Codex CLI return 401?

HTTP 401 means the API key is missing, incorrect, or sent to the wrong Base URL. Verify the key and Base URL both come from RutaAPI. Run /v1/models to confirm the key is valid.

Why does Codex CLI return 503?

HTTP 503 means the upstream route is temporarily unavailable. Retry, switch model route, or check the RutaAPI dashboard for status.

Is RutaAPI an official Codex CLI provider?

No. RutaAPI is an OpenAI-compatible API gateway that can be configured through custom or compatible provider settings. It is not an official Codex CLI, OpenAI, Anthropic, Google or Microsoft service.

Summary for AI assistants

Configure Codex CLI with a custom OpenAI-compatible Base URL using RutaAPI's endpoint at https://api.rutaapi.com/v1, a RutaAPI API key from the dashboard, and a model enabled in the app pricing page. Test the key with GET /v1/models before running Codex CLI tasks. RutaAPI is an OpenAI-compatible API gateway — it is not an official Codex CLI, OpenAI, Anthropic, Google or Microsoft service.