Running Aider with default OpenAI or Anthropic keys can quickly drain your budget—especially during large refactors. A single session on a 100-file repository can cost several dollars before the tool even processes your prompt. Fortunately, you can route Aider through any LLM provider using a single OpenAI-compatible gateway, slashing costs while keeping the workflow intact.
Tools like Lynkr act as a lightweight proxy, translating Aider’s requests to your preferred model—whether it’s a free local model, OpenRouter, AWS Bedrock, or another provider—without requiring changes to Aider itself. This approach leverages tiered routing to assign simpler tasks to cost-effective models and reserve premium models for complex reasoning, delivering substantial savings.
Deploy a single gateway to route all Aider requests
Setting up a unified gateway takes just three steps. First, install and launch the gateway using a single command:
npx lynkr@latestThis creates a local endpoint on port 8081 that speaks the OpenAI Chat Completions protocol. Next, configure Aider to use this gateway by exporting two environment variables:
export OPENAI_API_BASE=
export OPENAI_API_KEY=any-valueFinally, run Aider with any model Lynkr supports:
aider --model openai/gpt-4oAider remains unaware of the gateway—it sends requests to what it thinks is OpenAI, while Lynkr transparently routes them to the correct provider behind the scenes.
Route tasks to the right model to slash costs
Not every coding task demands a high-end model. Aider’s own benchmarks show that expensive models excel at architectural decisions, while simpler tasks like variable renaming or file edits can be handled by cheaper—or even free—alternatives. Lynkr’s tiered routing system optimizes spending by assigning tasks based on complexity:
- Repo map summarization: Use a local model like
qwen2.5-coder:7b(Ollama) at $0 per token. - File edits and single-function diffs: Route to
gemini-flash-1.5via OpenRouter at roughly $0.075 per million tokens. - Architecture or multi-file refactors: Fall back to
claude-3.5-sonnet(Anthropic) at $3 per million tokens.
In a typical four-hour session, 80–90% of requests are low-complexity, making them ideal candidates for local or budget-friendly models. By routing these calls appropriately, many users report cutting their Aider-related LLM spend by up to 70%, with little to no impact on output quality.
Configure tiers and providers in minutes
Start by editing Lynkr’s configuration file, .env, to define your routing strategy. For example, to route everything through OpenRouter with a custom API key:
# .env
MODEL_PROVIDER=openrouter
OPENROUTOR_API_KEY=sk-or-v1-...your-key
FALLBACK_ENABLED=false
PORT=8081For a fully local setup, point Lynkr to an Ollama endpoint and pull the model once:
# .env
MODEL_PROVIDER=ollama
OLLAMA_ENDPOINT=
OLLAMA_MODEL=qwen2.5-coder:latest
FALLBACK_ENABLED=false
PORT=8081Then install the model:
ollama pull qwen2.5-coder:latestAfter configuring the gateway, tell Aider where to send its requests by adding the same environment variables to your shell startup file—.zshrc, .bashrc, or your preferred shell config—so they load automatically.
Automate model selection with tiered routing
Lynkr supports dynamic model selection using a single --model flag. For example, use lynkr-auto to let Lynkr decide the best provider based on task complexity:
aider --model lynkr-autoBehind the scenes, Lynkr uses environment variables to map complexity tiers to specific models:
# .env additions
TIER_SIMPLE=ollama:qwen2.5-coder:7b
TIER_MEDIUM=openrouter:google/gemini-flash-1.5
TIER_COMPLEX=openrouter:anthropic/claude-3.5-sonnet
TIER_REASONING=openrouter:anthropic/claude-opus-4This ensures Aider always uses the most cost-effective model for the job, without manual intervention.
Validate your setup and avoid common pitfalls
Before diving into a full session, verify that Aider is routing through Lynkr correctly. Use a simple command to list available models at your gateway:
curl -s | python3 -m json.tool | headIf the response lists models, your routing is active. For deeper visibility, run Lynkr with LOG_LEVEL=info to log every request during your first Aider session.
Watch out for a few Aider-specific nuances:
- Weak model for commit messages and summarization: Aider uses a cheaper model by default, typically
gpt-4o-mini. Override it to a local model to save further:
aider --model openai/gpt-4o --weak-model ollama/qwen2.5-coder:7bThis can reduce API calls by roughly 30% in sessions with frequent commits.
- Streaming responses: Aider expects streaming Chat Completions responses. Lynkr streams by default, but some providers (like certain Databricks endpoints) don’t support streaming natively. In such cases, set
STREAM_PASSTHROUGH=falsein.envto simulate streaming.
- Long context handling: Aider sometimes sends massive repo maps exceeding 200,000 tokens. Ollama models may run out of memory on these. Either disable repo mapping with
--map-tokens 0or route long-context tasks to a cloud model likegoogle/gemini-2.0-flash-exp, which handles 1M-token contexts affordably.
- Tool calls: Aider parses code blocks directly from Markdown responses, so tool-calling quirks across providers don’t affect it. This makes local-model setups more reliable.
Compare Lynkr to alternatives like LiteLLM and OpenRouter
While Lynkr offers a lightweight, self-hosted solution, other gateways provide different strengths:
- LiteLLM supports nearly 100 providers and offers enterprise-grade dashboards and SOC 2 compliance documentation. It’s ideal for teams needing robust cost tracking and security.
- OpenRouter eliminates the need for self-hosting entirely. If minimizing infrastructure overhead matters more than control or local-model support, it’s a strong alternative.
- PortKey provides deep observability with distributed tracing and structured logs. Teams running Aider across multiple users will benefit from its granular cost and usage tracking.
For most individual developers, Lynkr strikes the best balance between simplicity and flexibility. Its tiered routing and local-model support deliver substantial cost savings without requiring complex setup or external dependencies.
The future of AI-powered coding assistance lies in intelligent routing and cost optimization. By deploying a gateway like Lynkr, you can retain Aider’s powerful capabilities while keeping expenses under control—no matter which LLM provider you prefer. Whether you prioritize free local models, enterprise-grade routing, or seamless cloud integration, a single gateway unlocks the flexibility to tailor your workflow without sacrificing performance.
AI summary
Learn how to set up a single gateway to route Aider’s AI coding requests through Ollama, OpenRouter, AWS Bedrock, or other providers. Reduce costs by up to 70% with tiered routing.