">
 

Run Aider on Ollama, Bedrock, or Any LLM Provider — One Gateway, Every Model

Iniciado por joomlamz, 30 de Maio de 2026, 18:00

Respostas: 0   |   Visualizações: 14

Tópico anterior - Tópico seguinte

0 Membros e 1 Visitante estão a ver este tópico.

Run Aider on Ollama, Bedrock, or Any LLM Provider — One Gateway, Every Model



Tópico: Run Aider on Ollama, Bedrock, or Any LLM Provider — One Gateway, Every Model
Categoria: Tutoriais | Programação & Tecnologia
Idioma Principal: Português (Conteúdo de Tecnologia)

Descrição do Conteúdo / Informações:
-------------------------------------------------------------------------
Aider is the best terminal AI coding tool I've used. But by default it sends every diff through your OpenAI or Anthropic key, which gets expensive fast on real refactors — a single 100-file repo map can torch a few dollars before Aider even reads your prompt.

This post shows how to run Aider against any LLM provider — Ollama for free local runs, OpenRouter for mixed-provider routing, AWS Bedrock for the enterprise plate — through a single OpenAI-compatible endpoint. I'll use Lynkr, the self-hosted gateway I maintain, but the pattern works with any OpenAI-compatible proxy.

Full disclosure: I build Lynkr. I'll point out where it loses to LiteLLM and OpenRouter further down so you can make an honest call.



The setup in three commands


# 1. Start the gateway
npx lynkr@latest

# 2. Point Aider at it
export OPENAI_API_BASE=http://localhost:8081/v1
export OPENAI_API_KEY=any-value

# 3. Run Aider with any model name Lynkr knows about
aider --model openai/gpt-4o

That's it. Aider speaks the OpenAI Chat Completions protocol; Lynkr speaks it back and quietly translates the call to whichever upstream provider you've configured (Ollama, Bedrock, Anthropic, Azure, OpenRouter, Databricks, llama.cpp, LM Studio, ...). Aider has no idea it's talking to a router.



Why bother? The cost math


Aider's own leaderboard shows GPT-4o and Claude 3.5 Sonnet at the top — but you don't need a $3-per-million-tokens model to rename a variable. You need it for the architecture decisions.

Lynkr's tier routing splits the work:

Aider call type
Routes to
Cost

Repo map summarization

qwen2.5-coder:7b (Ollama, local)
$0

File edits, single-function diffs

gemini-flash-1.5 (OpenRouter)
~$0.075/M

Architecture / multi-file refactors

claude-3.5-sonnet (Anthropic)
$3/M

On a typical 4-hour Aider session, 80–90% of the calls are repo-map and small-diff calls. Routing those to local + cheap models while keeping Claude Sonnet for the hard reasoning has cut my own Aider spend by roughly 70%. Your mileage will vary based on how much architectural work you do.



Configuration walkthrough




Step 1 — Install and start Lynkr


npx lynkr@latest

First run creates a .env file in your current directory. The minimal config for "everything goes through OpenRouter":

# .env
MODEL_PROVIDER=openrouter
OPENROUTER_API_KEY=sk-or-v1-...your-key
FALLBACK_ENABLED=false
PORT=8081

For "everything local, free, no API bills":

# .env
MODEL_PROVIDER=ollama
OLLAMA_ENDPOINT=http://localhost:11434
OLLAMA_MODEL=qwen2.5-coder:latest
FALLBACK_ENABLED=false
PORT=8081

Then ollama pull qwen2.5-coder:latest once and you're done.



Step 2 — Tell Aider where the gateway is


Aider reads two standard env vars: OPENAI_API_BASE and OPENAI_API_KEY. Lynkr ignores the key value but Aider expects one to be set, so put any string.

export OPENAI_API_BASE=http://localhost:8081/v1
export OPENAI_API_KEY=dummy

Add those to your shell rc file (.zshrc, .bashrc, or your fish config) and forget about them.



Step 3 — Pick a model


The --model flag tells Aider which model to ask for. Lynkr looks at the model string, maps it to the upstream provider via your .env, and forwards the call.

# Use whatever model Lynkr's primary provider exposes
aider --model openai/gpt-4o

# Or — if you've configured tier routing — let Lynkr pick
aider --model lynkr-auto

The lynkr-auto model name (custom; works with the TIER_* env vars below) lets Lynkr score each prompt's complexity and pick a tier:

# .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-4



Step 4 — Verify the route


The fastest way to confirm Aider is hitting Lynkr (and not silently falling back to OpenAI):

curl -s http://localhost:8081/v1/models | python3 -m json.tool | head

If you see a list of models, you're routed. Lynkr also logs every request — start it with LOG_LEVEL=info and watch the terminal during your first Aider session.



Aider-specific gotchas


Aider's "weak model" for commit messages and summarization. Aider uses a cheaper model for non-code calls. By default it's gpt-4o-mini. You can override it to a free local model:

aider --model openai/gpt-4o --weak-model ollama/qwen2.5-coder:7b

This alone cuts ~30% of API calls if you do a lot of commits per session.

Streaming. Aider expects streaming Chat Completions responses. Lynkr streams by default, but if you've configured a provider that doesn't (some Databricks endpoints), set STREAM_PASSTHROUGH=false in .env and Lynkr will buffer + simulate streaming.

Long context. Aider sometimes sends 200k+ token repo maps. Local Ollama models will OOM on these. The honest answer: either set --map-tokens 0 to disable repo mapping (Aider still works, just less context), or route long-context calls to a cloud model with the TIER_REASONING=openrouter:google/gemini-2.0-flash-exp line above (Gemini Flash handles 1M-token contexts cheaply).

Tool calls. Aider doesn't use function/tool calls — it parses code blocks out of plain Markdown responses. This means tool-calling quirks across providers don't apply to Aider specifically, which is good news for local-model setups.



What Lynkr loses on vs. alternatives


A few I've benchmarked against:


LiteLLM has more providers (almost 100), better enterprise dashboards, and a longer track record. If you need SOC 2 compliance docs or Postgres-backed cost tracking, use LiteLLM.


OpenRouter doesn't require self-hosting at all. If "no infra" matters more to you than control or local-model support, OpenRouter is the right answer.


PortKey has the deepest observability — distributed tracing, structured logs, guardrails. If you're running Aider across a team and care about who-spent-what, PortKey will give you more than Lynkr.

Lynkr's reason to exist is: single Node binary, drop-in OpenAI base URL, first-class local-model support, tier routing built in. If those four match your shape, it's the lightest path. If you need any of what the others do better, use them.



Quickref


Aider env var
Lynkr role

OPENAI_API_BASE=http://localhost:8081/v1
Where Lynkr listens

OPENAI_API_KEY=dummy
Required by Aider, ignored by Lynkr

--model openai/gpt-4o
Forwarded as-is to the configured upstream

--model lynkr-auto
Triggers Lynkr's complexity-based tier routing

--weak-model ollama/qwen2.5-coder:7b
Free local model for commit messages



TL;DR


• Aider's default OpenAI/Anthropic setup is fine for hobby use, expensive for real work.

• Any OpenAI-compatible gateway turns it into a multi-provider tool with no Aider changes.

• Lynkr is one option for that gateway, optimized for self-hosting + local models + tier routing.

• LiteLLM, OpenRouter, and PortKey are stronger if you need enterprise features, hosted SaaS, or deep observability respectively.

Aider's GitHub: https://github.com/Aider-AI/aider

Lynkr's GitHub: https://github.com/Fast-Editor/Lynkr — star if you want to follow the next integration writeups (OpenHands, Roo Code, Zed are queued).


Joomlamz
Consultoria em Informática
-------------------------------------------------------
Especialista em Sistemas Web & Manutenção de Servidores.
A desenvolver o novo AplPortal com suporte a PHP 8.
Precisa de ajuda profissional? Contacte-me.

Tags: