LLMs for Developers
Large language models went from novelty to daily driver for a lot of engineers in just a couple of years — but most developers still use them as a black box. This guide opens the box at exactly the level that matters for writing code: what a token is, why context windows fill up, what temperature actually changes, how weak and strong models trade cost for capability, and why an LLM will confidently invent an API that doesn't exist. Understand these and you'll get better output, spend less, and know when to trust the model — and when to make it prove itself against your real code.
- What large language models (LLMs) actually do
- Tokens: the unit an LLM reads, thinks in, and bills
- Context windows and why bigger isn't free
- Temperature, top-p and how much the model gambles
- Weak vs strong models: capability, latency and cost
- Model routing: matching task complexity to the right LLM
- Hallucination and grounding: why LLMs invent APIs
- Cost, latency and caching in production
- Evaluating LLM output: don't trust, verify
What large language models (LLMs) actually do
A large language model (LLM) is, underneath, a next-token predictor. Trained on a vast corpus of text and source code, it learns the statistical structure of language well enough that, given a sequence of tokens, it can estimate a probability distribution over what token comes next — then sample one, append it, and repeat. That single mechanism, run on transformer neural networks with billions of parameters, is what produces everything from a code review to a working function. It is not a database you query and not a logic engine that proves things; it is a very good pattern completer.
Code is a near-ideal domain for this. It is highly structured, its idioms repeat across millions of public repositories, and correct output is often a small edit away from patterns the model has already seen thousands of times. That is why LLMs write plausible boilerplate, translate between languages, and explain unfamiliar code so well. But *plausible* is the operative word — the model completes patterns; it does not understand your specific repository, your invariants, or what actually runs in production unless you put that information directly in front of it.
Almost everything else in this guide falls out of that one design fact. Tokens exist because the model reads and writes in token units. Context windows exist because it can only attend to a bounded span of tokens at once. Temperature exists because the final step samples from a probability distribution. And hallucination exists because a fluent, high-probability continuation is not the same thing as a true one. Understand the mechanism and the rest stops being mysterious.
Tokens: the unit an LLM reads, thinks in, and bills
Before an LLM sees your prompt, a tokenizer chops it into tokens — subword chunks produced by a scheme like byte-pair encoding. A token is usually a few characters: ordinary English runs at roughly 1.3 tokens per word, or about 4 characters per token. Code tokenizes less evenly — long identifiers, punctuation, and indentation can each cost their own tokens — so a dense source file often uses more tokens than its raw character count would suggest.
Tokens are the currency of the entire system. Context limits are measured in tokens, latency scales with tokens generated, and API pricing is per token — counted separately for the input (your prompt) and the output (the completion), with output typically billed at a higher rate. A long back-and-forth chat quietly re-sends its whole growing history as input tokens on every turn, which is why costs creep up even when your latest message is short.
This is why *just paste the whole file* is a bad habit — you pay for every token whether or not it earns its keep. SlicerCode keeps prompts lean by feeding the agent a bounded, relevant slice per turn and auto-stubbing stale tool output instead of resending it, and you can cap the per-turn token budget in settings. Learn to think in tokens and you control both cost and speed.
- Rule of thumb: about 1.3 tokens per English word, or ~4 characters per token.
- You pay for input and output tokens separately — output is usually the pricier side.
- Code, JSON and long identifiers tokenize denser than prose; whole-file pastes add up fast.
Context windows and why bigger isn't free
The context window is the maximum number of tokens — prompt plus generated output — a model can consider in a single call. Modern windows are large (hundreds of thousands, sometimes a million-plus tokens), which tempts people to stuff everything in. But attention, the transformer's core operation, grows roughly quadratically with sequence length, so a fuller window means more compute, higher latency, and higher cost on every request.
Worse, the effective context is smaller than the advertised one. Research on long contexts documents a *lost in the middle* effect: models recall information placed at the very start or end of a long prompt far more reliably than the same information buried in the middle. Filling the window does not guarantee the model uses what you put there — position and relevance matter more than raw volume.
The winning move is curation, not maximalism — a discipline covered in depth in context engineering. Rather than dumping your repository into the prompt, SlicerCode hands the agent a targeted slice: the call graph for the code being changed, the specific flow, and real runtime values — high-signal context that fits in a small window instead of a haystack the model has to search.
Temperature, top-p and how much the model gambles
At each step the model outputs a probability distribution over the next token, and sampling parameters decide how it picks. Temperature scales the logits before the softmax: low temperature sharpens the distribution so the most likely token almost always wins; high temperature flattens it, making rarer tokens more likely and the output more varied. top-p (nucleus sampling) is a companion knob that restricts sampling to the smallest set of tokens whose probabilities sum to p.
For code you usually want low temperature — around 0 to 0.2 — so the model produces conventional, deterministic output instead of creative detours. Higher temperature is useful when you deliberately want variety: brainstorming approaches, generating several candidate names, or exploring alternatives. Note that temperature 0 is greedy but not always bit-for-bit reproducible across runs, because batching and floating-point differences on the serving side can still break ties differently.
The crucial thing temperature does *not* do is make the model smarter. It only changes how adventurous the sampling is. If you are getting wrong answers, cranking or dropping temperature will not fix them — the fix is better context and a clearer prompt, which is the whole point of prompt engineering.
- Low temperature (0–0.2): deterministic, conventional — the default for generating code.
- High temperature: more variety — good for brainstorming, bad for a production patch.
- Temperature changes risk, not intelligence — it won't turn a wrong answer into a right one.
Weak vs strong models: capability, latency and cost
Not all LLMs are the same size or skill. A strong model — more parameters, more training, better reasoning — handles multi-step problems, large diffs, and subtle bugs that a smaller model fumbles. A weak (small, fast) model is a fraction of the cost and latency and is perfectly good at boilerplate, renames, simple completions, and short factual answers.
The tradeoff is real money and real time. Because generation is autoregressive — one token at a time — latency is dominated by how many output tokens you ask for, and both cost and speed scale with model size. Running a frontier model to rename a variable is wasted spend; running a tiny model on a gnarly refactor produces a confident mess that loops and fails. There is no single *best* model, only the best model for a given task.
This is why serious LLM systems keep a portfolio of models rather than a favorite. The engineering question shifts from *which model is best?* to *which model is right for this request?* — which leads directly to routing.
Model routing: matching task complexity to the right LLM
Model routing automates that match. A lightweight classifier inspects each incoming request and decides whether it is trivial or hard, then dispatches it to a weak or strong model accordingly. Useful signals include prompt size, whether the message contains code fences, how many tools are in play, the number of turns in the conversation, and the task verbs — *rename* versus *design*, *fix a typo* versus *refactor this service*.
Done well, routing gives you most of a strong model's quality at a fraction of its bill, because the majority of real requests are easy. Done badly — always routing to the big model *to be safe* — you burn money and add latency to trivial edits. The routing layer, together with caching, is where a lot of the cost engineering in production LLM applications actually lives.
SlicerCode does this for you with a default model, slicercode-auto, that scores complexity from prompt size, code fences, tools present, message count and task verbs, then routes each request to a weak (fast, cheap) or strong model and falls back safely so it never errors out. You never pick a tier or manage API keys — the coding agent simply gets the right model per request.
Hallucination and grounding: why LLMs invent APIs
Because an LLM optimizes for a plausible continuation, not a verified one, it will sometimes produce a function signature, a config key, or an npm/PyPI package that looks completely reasonable and simply does not exist. This is hallucination, and its danger is precisely that the output is fluent — the fake API is formatted and named exactly like a real one. Invented package names are enough of a problem that attackers now register them to catch developers' autocomplete, a trick nicknamed *slopsquatting*.
The countermeasure is grounding: put real, retrieved facts into the context so the model completes from truth instead of memory. That means giving it actual file contents, the real call graph, live library documentation, or observed runtime values — the family of techniques known as retrieval-augmented generation and tool use. A grounded model still predicts tokens, but now the highest-probability continuation is anchored to your reality rather than the average of its training data.
This is the core of how SlicerCode works. Before the agent writes, it consults the analyzer's call graph and flows and the real runtime values captured from your running code, so it edits against how your project actually behaves instead of a guess. Grounding is the difference between an assistant that sounds right and one that is right.
Cost, latency and caching in production
In production, two numbers dominate: cost per request and time to answer. Both trace back to tokens. You pay for input and output tokens on every call, a chat re-sends its whole history each turn, and perceived speed is governed by time-to-first-token plus the number of output tokens streamed. Ask for less, and you spend less and wait less.
Caching is the highest-leverage optimization. Prompt (prefix) caching stores a stable leading chunk of the prompt upstream, so the repeated part of your context is reprocessed almost for free and returns faster on continuations. Response caching goes further: an identical re-ask can be served from an exact cache at essentially zero cost and latency, and a semantic cache can catch near-duplicate questions — as long as it is scoped per tenant so nothing leaks between accounts.
SlicerCode's backend applies all of this — a bounded per-turn context, history pruning and tool-output stubbing to keep prompts small, a stable prefix that always hits the upstream prompt cache, and optional exact and semantic response caches, every layer tenant-scoped. The practical payoff is also the fix for *why is my agent hanging*: lean prompts plus cache hits are what keep turns fast.
Evaluating LLM output: don't trust, verify
Public benchmarks like HumanEval and SWE-bench tell you how a model performs in general, but they say nothing about the specific patch it just wrote for your repository. For your code, the only evaluation that counts is concrete: does it compile, does it run, does it pass the tests, and does it satisfy the requirement? Treat model output as a proposal, not an answer.
The reliable pattern is a verification loop: generate, then compile and run and test, then feed any failure back to the model to fix — repeating until the checks pass. Deterministic, machine-checkable signals (a red test, a type error, a failed assertion) are worth far more than reading the diff and hoping. This is how you turn a probabilistic generator into a dependable tool.
SlicerCode builds that loop in. Its test generation is deterministic and self-repairing — it compiles, runs and repairs each suite until green rather than handing you a red test — and PRD validation scores an implementation against its spec across code, executed flow, remaining changes and tests, grounded in the values your code actually produced. Coverage is reported as real line coverage plus executed-flow coverage, so *is this tested?* becomes a number instead of a vibe.
Frequently asked questions
What is an LLM in simple terms?
An LLM (large language model) is a neural network trained on huge amounts of text and code that predicts the next token in a sequence. Run that prediction repeatedly and it produces coherent answers, code, and explanations — but it's pattern completion, not guaranteed truth.
How many tokens is a word?
As a rule of thumb, English text is about 1.3 tokens per word, or roughly 4 characters per token. Code, JSON and long identifiers tokenize more densely, so a source file usually uses more tokens than a plain-prose passage of the same character length.
What temperature should I use for code generation?
Keep it low — around 0 to 0.2 — so the output is deterministic and conventional. Raise the temperature only when you want variety, such as brainstorming several approaches; it controls randomness, not correctness, so it won't fix a wrong answer.
Why do LLMs hallucinate code and invent functions that don't exist?
Because an LLM generates the most plausible next tokens rather than verified facts, a fake-but-realistic function or package name can score high and get emitted. The fix is grounding: give the model real code, live docs and runtime values so its best continuation is anchored to reality.
Do bigger LLMs always write better code?
No. Strong models reason better on hard, multi-step tasks, but they cost more and run slower, and a small model is perfectly good for boilerplate, renames and simple edits. The right approach is matching each task to the smallest capable model — which is what model routing automates.
How can I reduce LLM API costs?
Send fewer tokens by curating context instead of pasting whole files, route easy requests to a cheaper model, and lean on caching — prompt-prefix caching makes repeated context nearly free and response caching serves identical re-asks at almost zero cost. SlicerCode applies all three automatically.
Keep learning
See it in your codebase
SlicerCode brings the agent, flow graphs, runtime capture, PRD validation and test generation into VS Code.