Intelligent AI Gateway for Coding Agents — task-aware routing, policy engine, transparent failover
Project description
Forge
Intelligent AI Gateway for Coding Agents — point every coding agent at one endpoint, and stop thinking about models.
Forge sits between your coding agents (Cline, Aider, Continue, …) and your LLM providers. It analyzes each request, picks the best available model for the task, and fails over transparently when a model is rate-limited or down.
Cline / Aider / Continue / RooCode ──▶ localhost:4000 ──▶ Forge ──▶ best model right now
Why not just LiteLLM? LiteLLM routes by model group. Forge routes by request content: it detects what you're doing (refactoring? debugging? writing docs?), filters out models that can't handle the request (no function calling? context too small?), keeps a conversation pinned to one model for prompt-cache hits, and scores the rest on live health, latency, and capability. Every routing decision is explainable — no black-box learned router.
Status: pre-release (v0.3-dev). Core routing, failover, policies, and Anthropic-format support work. The dashboard UI is still in progress. Expect breaking changes.
Features
- OpenAI-compatible API —
/v1/chat/completions(streaming included),/v1/embeddings,/v1/models - Anthropic-compatible API —
/v1/messageswith full streaming-event and tool-use conversion, so Claude Code can use any provider behind Forge - Policy engine — manage policies, not models: first-match YAML rules pick candidate pools by task/client/context size, with hard constraints like
allow_paid: false - Task-aware routing — request analysis → capability matrix → best model, with
auto:refactor-style hints when you know better - Hard compatibility filter — requests needing tools / JSON mode / vision / large context never land on a model that can't serve them
- Session affinity — the same conversation stays on the same model (prompt-cache hits, consistent behavior); moves only on failover
- Proactive rate limiting — per-provider token buckets steer traffic away before the 429 happens; reactive cooldowns remain as the safety net
- Self-healing failover — 429 → instant cooldown (honors
Retry-After) → next candidate; context-overflow → retry on a bigger-context model; all invisible to the client - Explainable decisions —
POST /v1/route/explaindry-runs any request and shows the matched policy, every exclusion reason, and the score table - Auto discovery & hot reload — new provider models register at boot; edit
forge.yamlandPOST /admin/reloadwithout dropping in-flight requests - Real metrics — per-model latency (TTFT for streams), success rate, token usage, cost — stored locally in SQLite
Quickstart
Requires Python 3.10+.
git clone https://github.com/WhiteJbb/forge.git
cd forge
python -m venv .venv
.venv/Scripts/pip install -e . # Windows (macOS/Linux: .venv/bin/pip install -e .)
export NVIDIA_API_KEY=nvapi-... # or put it in .env
forge doctor # check keys & provider connectivity
forge start
Forge listens on http://127.0.0.1:4000. Check http://127.0.0.1:4000/health to see your model pool, or run forge models for an offline view. No config yet? forge init generates a forge.yaml from the API keys it finds in your environment.
If the
forgecommand collides with Foundry's on your PATH, use theforge-gwalias.
Configuration lives in forge.yaml — providers, model tiers/capabilities, cooldowns, timeouts. It ships with a working NVIDIA free-tier setup.
Connect your coding agent
Use model auto and let Forge choose, or auto:debug / auto:refactor / auto:documentation / auto:testing to force a task type. Unless you set FORGE_API_KEY, the API key can be any non-empty string.
Cline (VS Code) — Settings → API Provider: OpenAI Compatible
Base URL: http://127.0.0.1:4000/v1
API Key: forge
Model ID: auto
Continue — config.json:
{
"models": [{
"title": "Forge",
"provider": "openai",
"model": "auto",
"apiBase": "http://127.0.0.1:4000/v1",
"apiKey": "forge"
}]
}
Aider
export OPENAI_API_BASE=http://127.0.0.1:4000/v1
export OPENAI_API_KEY=forge
aider --model openai/auto
Claude Code
export ANTHROPIC_BASE_URL=http://127.0.0.1:4000
export ANTHROPIC_API_KEY=forge # or your FORGE_API_KEY
Claude Code speaks the Anthropic Messages API; Forge converts it (tool use and streaming events included) and routes to whatever provider your policies choose.
Every response carries routing metadata in headers: X-Forge-Model, X-Forge-Tier, X-Forge-Task, X-Forge-Attempt.
Endpoints
| Endpoint | Description |
|---|---|
POST /v1/chat/completions |
OpenAI-compatible chat, streaming + transparent failover |
POST /v1/messages |
Anthropic-compatible chat (Claude Code) |
POST /v1/route/explain |
Dry-run: matched policy, exclusion reasons, score table |
POST /v1/embeddings |
Embeddings (explicit model id) |
GET /v1/models |
Model pool + auto aliases |
GET /health |
Gateway + per-model health |
GET /v1/stats |
Usage / latency / cost metrics (JSON) |
GET /dashboard |
Dashboard data (JSON), incl. throttle state |
POST /admin/reload |
Hot-reload forge.yaml (loopback only) |
POST /admin/cooldown/{model}/clear |
Manually clear a cooldown (loopback only) |
Privacy
Forge runs entirely on your machine. No telemetry, ever. Prompt and response bodies are never stored — metrics keep numbers only (latency, token counts, status codes). API keys are read from environment variables and never written to disk or logs.
Roadmap
See DESIGN.md — up next: YAML policy engine ("route by policy, not by model"), Anthropic /v1/messages support for Claude Code, proactive rate limiting for free tiers, /v1/route/explain dry-run, and a web dashboard.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file forge_gateway-0.3.0.dev0.tar.gz.
File metadata
- Download URL: forge_gateway-0.3.0.dev0.tar.gz
- Upload date:
- Size: 122.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f322ea48b766342a67b5360ddb0d54700d42e4365a53673420ca273ef6c6ece
|
|
| MD5 |
47ab2979892fc21428ee1802622cb4a3
|
|
| BLAKE2b-256 |
c29399e62cafafb1c69f70a5243847be775f626c6ff0e2b2686b2e3b02569a53
|
File details
Details for the file forge_gateway-0.3.0.dev0-py3-none-any.whl.
File metadata
- Download URL: forge_gateway-0.3.0.dev0-py3-none-any.whl
- Upload date:
- Size: 69.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a049af7493c50ed6a4a625fc837a4adcbd9498d035e5de3d8fb2cc9d0b46908d
|
|
| MD5 |
43d6268625974bdf939e2d716dd6ac8f
|
|
| BLAKE2b-256 |
3dfb0fc5060f16176befa295c2784ace032e6ce110fbf8129a1f196d1bd53f46
|