Use Cases + Implementation

How do you reduce the cost of code generation with model routing?

Code generation is output-heavy: long completions dominate cost more than input. Route autocomplete, boilerplate and test scaffolding to fast coder tiers such as plugsky-coder-fast, escalate architectural edits and multi-file reasoning to stronger coding models, and gate every downgrade behind your test suite. Cache repeated prompts and keep file context minimal.

Key facts

Router modelplugsky-fusion escalates per request across coding and general tiers (live)
Coder tiersplugsky-coder and plugsky-coder-fast are live coding models
Models30+ models; route completions by task complexity
Strategycost_saver for boilerplate, balanced for edits, max_quality for architecture
PricingFlat monthly self-serve plans with no per-token charges on self-serve
Free tierplugsky-micro and plugsky-lite on the free plan, no card required
StreamingLive via server-sent events for progressive completions
RoadmapThe batch endpoint is coming soon for offline generation jobs

TL;DR

  • Output length drives code-generation cost; cap it per task.
  • Use fast coder tiers for autocomplete, boilerplate and tests.
  • Escalate multi-file edits and architecture questions.
  • Gate any tier downgrade behind passing tests, not vibes.
  • Send the minimum file context needed for the edit.

How it works, step by step

  1. Categorise code requests: completion, boilerplate, tests, refactor, architecture, debugging.
  2. Assign a default tier per category, starting conservatively and moving one category at a time.
  3. Cap max_tokens per category and stop at a natural completion boundary.
  4. Build a test-based evaluation set: run generated code, don't just read it.
  5. Downgrade a category only when its tests pass at the same rate as before.
  6. Cache repeated prompts such as templates and scaffolds.
  7. Review per-category quality and generation volume monthly.
1Categorise coderequests:completion,2Assign a defaulttier per category,starting3Cap max_tokens percategory and stopat a natural4Build a test-basedevaluation set: rungenerated code,5Downgrade acategory only whenits tests pass at6Cache repeatedprompts such astemplates and

Try it yourself

Open the best-model-for-coding selector →

Why code costs more per call

Generated code is long. A completion that writes a module can emit thousands of tokens where a chat reply emits dozens, so output volume, not input, is usually the bill. Long inputs make it worse: pasting whole repositories into context raises the input side and degrades instruction-following at the same time.

The response is task segmentation. Autocomplete and boilerplate have narrow, predictable outputs; refactors and debugging need more reasoning; architecture questions need the strongest model and a human in the loop. Assigning one model to all four categories means overpaying for the easy three.

A two-tier coding pipeline

Most teams settle on a fast coder tier plus a strong reasoning tier. Use plugsky-coder-fast or similar for completions, tests and repetitive edits, and escalate to a stronger coding model for multi-file changes, unfamiliar APIs and debugging sessions. Fusion strategies express the default; per-key or per-feature rules pin exceptions for critical repositories.

  • Send the current function plus direct dependencies — not the whole file tree.
  • Ask for a diff or a patch rather than a full rewrite; output is the expensive part.
  • Cap completion length and continue explicitly if the answer was truncated.
  • Log which tier produced which suggestion so quality issues are attributable.

Testing is the quality gate

Code quality is measurable, which makes routing evidence-based. Run generated code through the test suite instead of reading it, and compare pass rates per category per tier. A fast model that passes the same tests at the same rate is a genuine saving; one that needs two review cycles is not.

Re-run the evaluation after model updates, prompt changes and framework upgrades, because all three shift performance. On self-serve plans there are no per-token charges, so the practical effect of routing is latency and throughput rather than a variable bill; see the live pricing page for plan detail. Build on the free plan with plugsky-micro and plugsky-lite, and use the 14-day full-access trial to compare coding tiers on your own repositories.

Honest comparison

Code taskRouted pipeline on PlugskyStrongest model alwaysOne cheap model always
Autocomplete and boilerplateFast coder tierStrong tier for triviaOften adequate
Multi-file refactorEscalated to strong coderNative strengthMisses context
DebuggingEscalated with logsNative strengthWeak reasoning
Output lengthDiff-style, cappedFull rewrites unless promptedVerbose or truncated
Quality evidenceTest pass rates per tierUsually unmeasuredUsually unmeasured

Frequently asked questions

Why is code generation expensive?

Generated code is long, and output tokens dominate cost. Pasting large context also adds input tokens and can reduce output quality, so output length and context trimming are the main levers.

Which model should handle autocomplete?

A fast coder tier such as plugsky-coder-fast handles completions, boilerplate and tests well. Escalate multi-file edits, debugging and architecture questions to stronger coding models.

How do I verify a cheaper model is good enough?

Run generated code through your test suite and compare pass rates per category per tier. Reading the output is not evidence; tests are.

Should I send the whole repository as context?

No. Send the function being edited plus its direct dependencies, and reference interfaces rather than pasting implementations. Smaller context is cheaper and usually more accurate.

Do I need a diff or a full file?

Ask for patches or diffs. Output is the expensive side of the request, and full rewrites also create review noise.

Is the batch endpoint available?

Not yet — batch is coming soon. For large offline generation jobs today, use bounded-concurrency workers with a queue and per-job status.

How does routing interact with flat pricing?

Self-serve plans are flat monthly with no per-token charges, so routing mainly affects latency and throughput. See the live pricing page for current plans.

Can I test coding tiers for free?

Yes. Start on the free plan with plugsky-micro and plugsky-lite, and use the 14-day full-access trial to benchmark coding models on your repositories.