my-free-code README

The project's README from github.com/hkqr/my-free-code. As one markdown file: README.md.

My Free Code v0.8

A multi-provider gateway for Claude Code and other coding agents.

It is an independent implementation. It is not affiliated with Anthropic.

What v0.8 includes

Gateway protocols

Agent features

Provider layer

The catalog contains the broad provider set used by the project:

NVIDIA NIM, OpenRouter, Groq, OpenAI, xAI, QwenCloud, Together, DeepInfra, SiliconFlow, Nebius, Chutes, Featherless, ZenMux, W&B Inference, Azure OpenAI, Google AI Studio, Google Vertex, DeepSeek, Mistral, Codestral, OpenCode Zen, OpenCode Go, Vercel AI Gateway, Amazon Bedrock, Hugging Face, Cohere, GitHub Models, Wafer, Kimi, Kimi Code, MiniMax, Cerebras, SambaNova, Kilo, Fireworks, Novita, Cloudflare Workers AI, Z.ai, TokenRouter, NaraRoute, Poolside, LLM7, Ollama Cloud, LM Studio, llama.cpp and Ollama.

Provider entries are not fake claims of universal support: providers with unusual authentication/protocols require a dedicated adapter. The common OpenAI-compatible providers use the shared transport.

Coding-agent launcher layer

The architecture has launcher adapters for:

A launcher simply prepares the local proxy environment and delegates arguments to the installed client.

Architecture

             Coding Agents / IDEs
                      |
          +-----------+-----------+
          |                       |
    Anthropic Messages       OpenAI Responses
          |                       |
          +-----------+-----------+
                      |
                FastAPI Gateway
                      |
                Model Router
                      |
          +-----------+-----------+
          |                       |
       Primary                  Fallbacks
          |                       |
          +-----------+-----------+
                      |
              Provider Runtime
                      |
       +--------------+--------------+
       |              |              |
 OpenAI-compatible  Specialized   Local
     adapter          adapter     runtime
       |              |              |
     APIs          provider API  Ollama/LM Studio

The architecture deliberately separates wire protocols from routing and provider code. This mirrors the important architectural boundary in the current reference project: HTTP adapters, application routing/execution, provider runtime, CLI adapters and optional messaging are separate concerns. citeturn0search0

Install

Python 3.10+.

python -m venv .venv

Windows:

.venv\Scripts\Activate.ps1
python -m pip install -r requirements.txt
copy .env.example .env

macOS/Linux:

source .venv/bin/activate
python -m pip install -r requirements.txt
cp .env.example .env

Start:

python -m my_free_code

Default address:

http://127.0.0.1:8082

Configure a model

Example:

MODEL=open_router/openrouter/free
MODEL_SONNET=deepseek/deepseek-chat
MODEL_HAIKU=groq/llama-3.3-70b-versatile
MODEL_OPUS=nvidia_nim/meta/llama-3.3-70b-instruct
FALLBACK_MODELS=deepseek/deepseek-chat,ollama/llama3.1

Then set the corresponding API keys in .env.

The public model identity stays as the gateway model even when a request is routed to another upstream provider.

Claude Code

$env:ANTHROPIC_BASE_URL="http://127.0.0.1:8082"
$env:ANTHROPIC_AUTH_TOKEN="local"
$env:CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY="1"
claude

Or:

python -m my_free_code.cli.mfc claude

Other clients

The launcher abstraction supports:

python -m my_free_code.cli.mfc codex
python -m my_free_code.cli.mfc pi
python -m my_free_code.cli.mfc opencode
python -m my_free_code.cli.mfc cline
python -m my_free_code.cli.mfc hermes
python -m my_free_code.cli.mfc deepseek-harness
python -m my_free_code.cli.mfc grok
python -m my_free_code.cli.mfc muse

The installed client must already exist on PATH.

Routing and fallback

For:

MODEL_SONNET=deepseek/deepseek-chat
FALLBACK_MODELS=groq/llama-3.3-70b-versatile,ollama/llama3.1

a Sonnet request follows:

Claude Code
    |
    v
deepseek/deepseek-chat
    |
    | failure before output
    v
groq/llama-3.3-70b-versatile
    |
    | failure before output
    v
ollama/llama3.1

Once a streaming response has committed output, the gateway does not silently switch providers and duplicate the turn.

Reasoning

The gateway accepts Claude-style thinking intent and keeps it separate from provider-specific request translation.

Supported normalized modes:

auto
on
off

and optional effort:

low
medium
high

Provider adapters can map the normalized reasoning policy to their documented upstream fields.

Admin

Open:

http://127.0.0.1:8082/admin

Authenticated JSON endpoints:

GET /api/admin/status
GET /api/admin/models
GET /api/admin/providers

Local models

Ollama:

OLLAMA_BASE_URL=http://127.0.0.1:11434/v1
MODEL=ollama/llama3.1

LM Studio:

LM_STUDIO_BASE_URL=http://127.0.0.1:1234/v1
MODEL=lmstudio/qwen3.5-coder

llama.cpp:

LLAMACPP_BASE_URL=http://127.0.0.1:8080/v1
MODEL=llamacpp/my-model

Security

This is intended for local use.

Tests

pytest -q

The repository includes deterministic tests for routing, protocol conversion, auth, reasoning, model catalog and streaming primitives.

Project structure

my-free-code/
├── my_free_code/
│   ├── api/
│   │   ├── routes.py
│   │   └── admin_routes.py
│   ├── cli/
│   │   ├── claude.py
│   │   ├── launchers.py
│   │   └── mfc.py
│   ├── core/
│   │   ├── anthropic.py
│   │   ├── responses.py
│   │   ├── reasoning.py
│   │   ├── failures.py
│   │   ├── streaming.py
│   │   └── model_catalog.py
│   └── providers/
│       ├── catalog.py
│       ├── adapters.py
│       ├── specialized.py
│       └── runtime.py
├── tests/
├── ARCHITECTURE.md
├── .env.example
├── requirements.txt
├── pyproject.toml
└── README.md

License

MIT.

my-free-code (hkqr/my-free-code)

Searching Database…

这是什么?My Free Code 是一个开源网关,架在 Claude Code 这类编程智能体和几十家 LLM 提供商之间,负责模型路由、流式传输、工具调用、推理透传以及提供商之间的回退。
这是我要导入的库,还是在本地跑的服务器?它是你自己运行的独立本地服务器,暴露兼容 Anthropic Messages 和 OpenAI Responses 的 HTTP 端点,外加一个本地管理界面,不是导入代码的库。
怎么让它跑起来?安装 Python 3.10+,然后运行自带的 Windows 或 macOS/Linux 启动脚本;它会在本地默认地址上把代理跑起来,然后你把编程智能体指向这个地址就行。
目录里的每个提供商都要 API 密钥吗?不用,只为你真正想路由过去的提供商准备——把这些密钥加进你的 .env 文件就行;目录里既有 OpenAI、OpenRouter 这样的云提供商,也有 Ollama、llama.cpp 这样的本地运行时。
如果某家提供商在响应中途挂了,它会悄悄换一家吗?不会。回退只在响应还没开始流式输出之前生效;一旦输出已经落定,网关不会再切换提供商、也不会把这一轮重复一遍。
把它暴露到公网上安全吗?不安全,它就是为本地使用设计的——把主机绑定到 127.0.0.1,设置一个真实的鉴权令牌,绝不把 Admin 端点直接暴露到公网。
可以通过这个网关启动哪些编程智能体?已有针对 Claude Code、Codex、Pi、OpenCode、Cline、Hermes、DeepSeek Harness、Grok Build 和 Muse Code 的启动器适配器;每个启动器只是准备一下本地代理环境,然后交给已经装好的客户端去跑。
可以完全用本地模型代替云提供商吗?可以——Ollama、LM Studio 和 llama.cpp 都可以作为提供商,你可以把请求路由到本地托管的模型,与云模型并用,或者完全取代云模型。
它支持 Claude 的推理/思考模式吗?支持,它接受 Claude 风格的思考意图,把它归一化成带可选努力程度的通用推理模式,提供商适配器再把它映射成各家上游自己的思考字段。
我的提供商凭据会泄露给其他提供商吗?不会——凭据按提供商留在你本地的环境/配置里,绝不会转发给另一家提供商。
Creator
hkqr
Size
0.7 MB
Stars
624
Updated
CommitOct 17
Age
1mo
Commits · 90 Days