Route Codex4Less Models Through LiteLLM: Custom Endpoint Setup
LiteLLM is an open-source LLM gateway: it exposes one OpenAI-compatible API locally and routes each request to the upstream provider you configure. This guide runs the LiteLLM Proxy on your machine with Codex4Less as the upstream provider:
Your app → local LiteLLM Proxy (127.0.0.1) → Codex4Less API → selected modelEvery step below — proxy startup, model alias, a live request, upstream verification and the common error cases — was executed against Codex4Less with litellm 1.105.1. Commands were run on Linux.
Two keys, two different jobs
Before the configuration, understand the two keys involved — mixing them up is the most common mistake:
| Key | Purpose | Where it goes |
|---|---|---|
| **Codex4Less API key** (`sk-...`) | Authenticates your proxy **to Codex4Less** | Environment variable referenced by the config (never written into the YAML) |
| **LiteLLM gateway key** (your master key) | Authenticates **your clients to the proxy** | Sent by clients as `Authorization: Bearer ...` |
Your applications only ever see the gateway key. The Codex4Less key stays in the proxy's environment.
Prerequisites
- Python environment for LiteLLM (the official install uses pip; a
uv/Docker path also exists — see the official proxy quickstart). - A Codex4Less account and API key: codex4less.com/register.
- A terminal. This guide's tests ran on Linux; commands are standard on macOS as well.
Step 1 — Create Your Codex4Less API Key
- Open API Keys in the dashboard: codex4less.com/dashboard/api-keys
- Create a key, copy the
sk-...value and keep it out of files. It is shown only once.
Step 2 — Install LiteLLM
The official method:
pip install "litellm[proxy]"
litellm --versionOn systems without pip, the same package installs cleanly with uv (this is how the tests for this guide were installed):
uv tool install "litellm[proxy]"
litellm --versionAt the time of writing this installs LiteLLM 1.105.1.
Step 3 — Write the Configuration
Create litellm-config.yaml:
model_list:
- model_name: codex4less-sol
litellm_params:
model: openai/gpt-6.1-sol
api_base: https://api.codex4less.com/v1
api_key: os.environ/CODEX4LESS_API_KEY
general_settings:
master_key: os.environ/LITELLM_MASTER_KEYWhat each part does:
- `model_name: codex4less-sol` — the alias your clients will call. Pick anything memorable.
- `model: openai/gpt-6.1-sol` — the upstream model. The
openai/prefix tells LiteLLM to use its OpenAI-compatible handler; the remainder is the Codex4Less model ID (see Step 4). - `api_base: https://api.codex4less.com/v1` — the Codex4Less API root. Keep the
/v1suffix (LiteLLM's docs note that a missing/v1typically causes “Not Found” errors). - `api_key: os.environ/CODEX4LESS_API_KEY` — LiteLLM reads the upstream key from the environment. The secret never appears in the YAML.
- `master_key: os.environ/LITELLM_MASTER_KEY` — the gateway key your clients must present.
Step 4 — Choose the Upstream Model
The authoritative Codex4Less catalog: codex4less.com/pricing and GET https://api.codex4less.com/v1/models.
This guide uses `gpt-6.1-sol` (verified end-to-end through the proxy; gpt-5.6-sol answered the same API tests). To expose several models, add more entries with different aliases pointing at different model IDs — the alias is a local name, the ID after openai/ is what Codex4Less receives.
Step 5 — Start the Proxy
export CODEX4LESS_API_KEY="sk-..." # your Codex4Less key
export LITELLM_MASTER_KEY="sk-choose-a-strong-local-key" # your gateway key
litellm --config litellm-config.yaml --host 127.0.0.1 --port 4010The proxy prints Uvicorn running on http://127.0.0.1:4010 when ready.
Security: bind to 127.0.0.1 for local quickstarts. A proxy reachable from the network needs proper key management (virtual keys/database, TLS, network controls) — do not expose an open gateway.Step 6 — Verify the Route
With the proxy running, list models through it (gateway key, not the Codex4Less key):
curl http://127.0.0.1:4010/v1/models -H "Authorization: Bearer $LITELLM_MASTER_KEY"Observed: the alias list ["codex4less-sol"]. Now a real request:
curl http://127.0.0.1:4010/v1/chat/completions \
-H "Authorization: Bearer $LITELLM_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"codex4less-sol","messages":[{"role":"user","content":"Reply with exactly: VIA_LITELLM"}]}'Observed reply: VIA_LITELLM, with model: "codex4less-sol" in the response. Finally, prove the request really passed through Codex4Less: open Dashboard → Usage at codex4less.com/dashboard/usage — during the tests for this guide, each proxy request appeared there within seconds with its model and token counts.
Error cases (tested)
- Unknown alias (e.g.
bilinmeyen-alias): the proxy rejects the request locally with an invalid-model error pointing you to/v1/models— no upstream call is made. - Wrong gateway key: rejected locally with a 400-class error. (Observed behavior in this no-database quickstart: an unknown key returns “No connected db.” — because without a DB, LiteLLM can only accept the single master key. Add a database if you need multiple virtual keys; see the [proxy docs](https://docs.litellm.ai/docs/proxy/docker_quick_start).)
- Bad Codex4Less key: the proxy forwards the request and Codex4Less answers 401 — that is the auth layer working upstream, and it shows in the proxy logs.
Optional — Python SDK instead of the proxy
If you prefer calling LiteLLM as a library (no gateway), the same values apply directly:
import litellm
response = litellm.completion(
model="openai/gpt-6.1-sol",
api_base="https://api.codex4less.com/v1",
api_key="sk-...", # Codex4Less key
messages=[{"role": "user", "content": "Hello"}],
)The proxy path is the focus of this guide because it centralizes keys and model aliases for multiple apps; use whichever fits your setup — don't mix both layers in one request path.
Troubleshooting
401 from the proxy
Your client's Authorization: Bearer ... doesn't match LITELLM_MASTER_KEY (or no key was sent). This 401 is local — the Codex4Less key is not involved.
401 from Codex4Less (visible in proxy logs)
CODEX4LESS_API_KEY is missing/incorrect/revoked inside the proxy's environment. Remember: export it in the same shell that starts litellm, then restart the proxy.
“Not Found” / 404
api_basemust include/v1(https://api.codex4less.com/v1) but must not include endpoint paths.- Model IDs are two namespaces: the alias (
codex4less-sol, local) and the upstream ID (gpt-6.1-sol, Codex4Less). A wrong upstream ID produces an upstream model error, not a local one.
Model appears but errors upstream
Run the same model ID directly against Codex4Less (POST https://api.codex4less.com/v1/chat/completions with your key) to isolate proxy issues from upstream availability. Catalog entries change — check the current list.
Port already in use
Pick another port (--port 4011) and update your clients accordingly.
FAQ
What's the difference between the LiteLLM SDK and the Proxy?
The SDK calls providers directly from your Python code. The Proxy runs a local gateway that your whole machine (or team) can use with one endpoint and one client key. This guide focuses on the proxy; both use the same openai/<model> + api_base mechanics.
Where should each key live?
Codex4Less key → environment variable referenced by os.environ/... in the config. Gateway key → master_key env var for the proxy, and in your clients' Authorization header. Neither belongs in committed files.
Is it safe to run the proxy on my machine?
Binding to 127.0.0.1 keeps it local. Exposing it requires virtual keys, TLS and network controls — see the LiteLLM docs.
Which Codex4Less models can I expose?
Any ID in the current catalog (pricing / GET /v1/models). One alias per model entry; verified example uses gpt-6.1-sol.
Do aliases and routing actually work?
Yes — the tested flow called only the local alias codex4less-sol through the proxy, and the upstream request arrived at Codex4Less as gpt-6.1-sol (confirmed in dashboard usage).
Conclusion and CTA
You now have a local OpenAI-compatible gateway in front of Codex4Less: one endpoint for your apps, one client key at the edge, and the Codex4Less key safely held by the proxy. Point any OpenAI-compatible client at http://127.0.0.1:4010 and you're set.
Ready to get started?
Create your Codex4Less account, generate an API key and wire it into the proxy config above.
Related reading: Connect Aider to Codex4Less · Using Codex CLI with Codex4Less · API documentation
