Experimenting with different LLM providers (OpenAI vs Anthropic vs OSS)

Picking an LLM provider based on leaderboard rankings is like hiring a chef because they scored well on a written exam.
The benchmarks are real, the scores are carefully measured, and they tell you almost nothing about whether that model will perform well on your specific product with your actual users. The only reliable way to make this decision is to run controlled experiments on your own data — the same way you'd test any product change that affects user outcomes.
This guide is for engineers and product teams who are actively building LLM-powered features and need a defensible process for choosing between OpenAI, Anthropic, and open-source alternatives. Here's what you'll learn:
- Why static benchmarks fail to predict production behavior — and what to use instead
- The five dimensions every LLM provider comparison needs to measure: quality, latency, cost, reliability, and safety
- How to structure a controlled experiment with proper randomization, confound controls, and metric instrumentation
- How to navigate the cost-quality trade-off between frontier models and cheaper open-source options
- How to turn experiment results into a production strategy with gradual rollouts, fallback logic, and multi-provider routing
The article moves in order from measurement framework to experiment design to deployment strategy. Each section builds on the last, so by the end you'll have a complete process — not just a checklist of things to consider.
Why static benchmarks don't tell you which LLM provider is right for your product
If you've spent any time evaluating LLM providers, you've almost certainly started with the leaderboards. Artificial Analysis, the Hugging Face Open LLM Leaderboard, Vellum — they're authoritative-looking, regularly updated, and full of the kind of quantitative rigor that makes a decision feel grounded.
And then you pick the top-ranked model, integrate it into your product, and something feels off. The responses are technically correct but tonally wrong. Latency is fine in testing but unpredictable under load. Users aren't engaging the way you expected. The benchmark said this model was best. What happened?
What happened is that benchmarks were never measuring what you actually needed to know.
Benchmarks measure narrow correctness, not production fit
Public leaderboards work by running models against standardized inputs, scoring outputs against predefined criteria, and aggregating the results into a ranking. The benchmarks themselves — GPQA Diamond for graduate-level reasoning, MMLU for broad knowledge coverage, AIME for mathematical problem-solving, SWE-Bench for software engineering tasks — are carefully constructed and genuinely useful for what they measure. The problem is what they measure.
As the evaluation team at HoneyHive puts it directly: "A benchmark with general scope but uncertain validity is fundamentally useless." Benchmarks deliver real signal only for narrow, objectively measurable tasks — the canonical example is SQL query generation against a predefined schema, where correctness is binary and the task definition is precise.
The moment you move to open-ended, context-dependent, user-facing tasks, the apples-to-apples comparison that makes benchmarks valid starts to break down. Your production prompt distribution doesn't look like the benchmark inputs. Your definition of a good response doesn't map to the scoring rubric. And aggregated scores hide variance on the specific subtasks that actually matter to your product.
Even the leaderboard providers acknowledge this. Prompts.ai notes explicitly that LLM comparison tools "lack task-specific insights" — a concession worth sitting with, given that task-specific performance is precisely what you're trying to evaluate.
The gap between rankings and production behavior
Here's the pattern that should make you skeptical: model providers report consistently climbing benchmark scores across every major leaderboard, yet practitioners building production systems report that real-world utility improvements feel much slower. The benchmarks say the models are getting dramatically better. The engineers shipping those models into products have a more complicated story to tell.
The structural reason for this gap is that benchmark evaluation criteria don't reflect user satisfaction. A model can score well on coherence metrics while producing responses that feel robotic to your users. It can ace factual recall benchmarks while failing at the specific domain knowledge your use case requires.
Artificial Analysis offers coherence and tone metrics alongside its performance data, which is more useful than raw accuracy scores — but still comes with "limited customization" for specific workflows. No leaderboard can capture whether a model's response style fits your brand voice, whether its refusal behavior is calibrated to your risk tolerance, or whether it handles the edge cases your users actually encounter.
Why task-specific experiments are the only reliable signal
The practitioner community has largely converged on this conclusion from experience. The team behind promptfoo, a benchmark harness built specifically because general benchmarks were insufficient, puts it plainly: test models on your own data and examples rather than extrapolating from general benchmarks. That recommendation comes from building evaluation infrastructure, not from theory.
The implication is methodological. If you want to know which LLM provider performs best on your customer support chatbot, your code review tool, or your document summarization pipeline, you need to run controlled experiments on your own data, with your own prompts, measuring outcomes that reflect what your users actually care about.
Benchmark rankings are a reasonable way to narrow the field — they can tell you which models are worth including in your evaluation. But the decision itself requires a different methodology entirely: structured experimentation with statistical rigor, the same kind you'd apply to any product change with measurable user impact.
This guide is for engineers, PMs, and data scientists who are building LLM-powered features and need a defensible process for choosing between providers — not a benchmark lookup, but a controlled experiment with statistical rigor. By the end, you'll have a complete framework for designing provider comparisons, instrumenting them correctly, and translating results into a production routing strategy.
Here's what the guide covers:
- The five dimensions to measure — quality, latency, cost, reliability, and safety — and what to instrument for each
- How to structure a controlled experiment — randomization, confound prevention, and the inference log fields that make downstream analysis possible
- The cost-quality trade-off — a 300x price gap that requires experimental validation, not assumptions
- Gradual rollouts, fallbacks, and multi-provider routing — how to move from experiment results to a production provider strategy
- A practical starting roadmap — what to do first, and the three infrastructure prerequisites that determine whether your data is trustworthy
The five dimensions you need to measure in any LLM provider comparison: quality, latency, cost, reliability, and safety
Before you run a single experiment comparing OpenAI, Anthropic, or an open-source alternative, you need to decide what you're actually measuring. This sounds obvious, but most teams skip it. They run a few prompts, read the outputs, and form an impression.
AWS's ML team calls this "vibes-based evaluation," and they're blunt about why it fails: subjective bias causes evaluators to favor confident-sounding outputs over accurate ones, limited sample coverage misses edge cases entirely, and inconsistency means two engineers reviewing the same outputs will reach different conclusions based on whether they weight brevity or factual detail. The result is experiment data you can't act on.
The five dimensions below give you a measurement vocabulary before you instrument anything. Each one requires a specific metric, not a general impression.
Quality: relevance, faithfulness, and task accuracy
Quality is the dimension teams think they're measuring when they're actually just pattern-matching on style. The three metrics that matter are output relevance (does the response address what was asked?), faithfulness (are factual claims accurate and grounded in the provided context?), and bias (does the model systematically skew outputs in ways that affect your use case?).
These need to be defined against your specific task — a customer support bot and a code generation tool require entirely different quality rubrics. Throughput without quality degradation is also part of this picture: a model that produces excellent outputs at low volume but degrades under load has a quality problem, not just a performance problem.
What to instrument: a task-specific scoring rubric applied to a representative sample of outputs, ideally with both automated scoring (LLM-as-judge or rule-based checks) and a human review set for calibration.
Latency: average response time and variance
Average latency is the metric everyone tracks. Latency variance is the one that actually breaks user experiences. Cloud-based LLMs have throttling limits that can't be removed even at the highest account tier — this creates unpredictable spikes that averages obscure entirely.
A provider with a 400ms median response time but a 95th-percentile of 4 seconds will feel broken to users even though the average looks acceptable. Artificial Analysis publishes latency data showing that the same underlying model can behave significantly differently across API providers — the model version alone doesn't determine your latency profile.
Metrics to track: p50, p95, and p99 latency per request, measured at the API call level, segmented by prompt length and time of day.
Cost: token economics and per-task spend
Token pricing is the headline number, but per-task cost is what your finance team will eventually ask about. Input and output tokens are priced separately, and prompt engineering choices that improve quality often increase token count — meaning cost and quality are coupled in ways that per-token pricing hides.
For on-premise or self-hosted open-source deployments, the cost model shifts entirely to infrastructure: GPU hours, memory, and serving overhead replace token fees.
What to log: total tokens consumed per task type (not per request), cost per successful completion, and cost variance across prompt template versions.
Reliability: uptime, error rates, and throttling behavior
Reliability under load is where provider differences become operationally significant. The relevant metrics are error rate (5xx responses, timeouts, and malformed outputs), throttling frequency (how often requests are rate-limited and at what volume thresholds), and quality consistency under sustained load.
A provider that performs well in a 100-request test may degrade measurably at production scale. Without systematic tracking, these degradations are invisible until they become incidents.
What to track: error rate by error type, rate-limit events per hour, and a quality sample drawn specifically from high-traffic periods rather than off-peak testing windows.
Safety: unsafe output rates, bias, and compliance behavior
Safety is the dimension most consistently missed by informal evaluation. Vibes-based testing rarely surfaces unsafe outputs because reviewers aren't specifically probing for them. The measurable signals here are unsafe output rate (responses that violate your content policy, measured against a defined test set of adversarial prompts), bias rates on demographic or sensitive topics, and compliance behavior — providers differ meaningfully in how they handle privacy-sensitive inputs and geopolitically contested content.
These differences matter for regulated industries and global products in ways that benchmark scores don't capture.
What to define: a predefined safety test suite run against each provider variant, with pass/fail criteria established before the experiment begins — not after you've seen the results.
Defining these metrics upfront does more than make your experiment interpretable. It forces the question of which dimensions actually matter for your use case, which is the prerequisite for any cost-quality trade-off decision.
A warehouse-native experiment platform makes it practical to track all five dimensions within a single experiment framework — so quality scores, latency percentiles, cost-per-request, error rates, and safety flag rates are all queryable against the same assignment data without routing inference logs through a third party.
Structuring a controlled experiment that produces defensible provider comparisons
The statistical principles behind A/B testing UI changes apply directly to provider comparisons — and most of the feature flag and analytics infrastructure you already have for product experimentation can be repurposed for this. The differences are specific: LLM experiments have a non-obvious randomization choice (per-request versus per-user assignment) that doesn't come up in UI testing, prompt templates need to be locked across arms in a way that CSS changes don't, and model version aliases can silently update underneath a running experiment in a way that a button color never will. The rest of this section explains each of those differences and how to control for them.
Per-request vs. per-user assignment: why the choice contaminates your metrics
The first decision is your unit of randomization: per-request, per-session, or per-user. Per-request randomization is technically simpler — each API call independently rolls a provider assignment — but it exposes the same user to inconsistent experiences within a single session, which contaminates any downstream metric that depends on user perception (satisfaction ratings, follow-up queries, task completion). Per-user assignment is cleaner for measuring outcomes that accumulate over time, and it's what you want if retention or engagement is in your metric set.
Consistent hashing is what makes per-user assignment stable without storing anything. Your flag SDK takes the user's ID and a fixed experiment identifier, runs them through a hash function, and always produces the same output — so the same user always routes to the same provider, on every request, without a database lookup or session cookie.
If you stored assignments in a cookie instead, you'd lose them on browser clears and get mixed exposure data. If model versions or experiment parameters change mid-test, sticky bucketing preserves the original assignment so you're not inadvertently mixing treatment conditions for users who are already mid-experiment.
Before you introduce a real provider difference, run an A/A test — both arms routing to the same provider — to confirm that your traffic splitting and metric collection are working correctly. It's a low-cost validation step that catches instrumentation bugs before they corrupt your actual comparison data.
On sample size: a practical floor is 200 conversion events per variation, which means if your LLM feature has a 10% task-completion rate, you need at least 4,000 users exposed before results are interpretable. Run the experiment for at least one full weekly cycle to avoid skewing results toward atypical traffic segments.
Keep in mind that LLM model versions can change during a long experiment window — pin to specific version strings, not aliases like gpt-4 that may silently update underneath you.
Prompt consistency and confound prevention
The most common confound in LLM provider experiments isn't traffic splitting — it's prompt variation. If your system prompt, few-shot examples, or temperature settings differ across arms, you're measuring prompt quality, not provider quality. All arms must use identical prompt templates, evaluated against the same input distribution.
Beyond prompts, three other confounds deserve explicit controls. Response caching needs to be disabled or applied consistently across arms; a cache hit on one provider and a cache miss on another will produce latency differences that have nothing to do with the provider itself.
Rate-limit differences are subtler: a provider hitting rate limits under load will show artificially high latency and elevated error rates, which looks like a provider quality problem but is actually a capacity problem at your traffic volume. Model version pinning matters because Artificial Analysis tracks over 500 AI model endpoints and shows that the same underlying model can vary significantly in latency and price across different API providers — your experiment variable needs to be defined as model + API endpoint + configuration, not just the model family name.
The inference log fields that make downstream analysis possible
Log the following per inference call: provider ID, model version string, time to first token, total completion time, input token count, output token count, and a request or session ID that joins to downstream user behavior events. Cost can be calculated directly from token counts multiplied by published rates, which means your billing exposure is instrumentable from the same log rather than requiring a separate data pull.
The join between inference logs and user outcome events is where most teams underinvest. If those two data streams live in different systems, you can measure latency and cost easily but can't connect them to whether the user actually completed their task or came back the next day.
A warehouse-native approach — where your experimentation platform connects directly to your own Snowflake, BigQuery, or Redshift instance rather than routing events through a third-party SaaS — keeps inference logs and behavioral data in the same place for analysis without moving PII outside your infrastructure.
One non-obvious design decision: if users are assigned to a provider at session start but only encounter the LLM feature partway through the session, your analysis should filter to users who actually received an LLM response. Including users who were assigned but never exposed inflates noise and reduces your ability to detect real differences.
This is the activation metric pattern — define the activation event (e.g., "user submitted a query that triggered an LLM call") and use it as the filter boundary for your outcome metrics.
Average metrics can also mask differential performance across user segments. A provider that performs well on English queries may degrade significantly for non-English speakers or domain-specific inputs. Segment your results before declaring a winner.
Feature flags as zero-latency traffic routing for provider experiments
Feature flags are the cleanest mechanism for routing requests to different providers without code deploys. The flag value — something like llm_provider: "openai" | "anthropic" | "llama-3-70b" — is evaluated locally in the application using a locally cached payload, which means the routing decision adds zero latency overhead to your inference pipeline.
That matters when latency is one of your primary measurement dimensions. The application reads the flag, routes the API call to the corresponding provider, and fires a tracking event that writes the assignment to your data warehouse.
SDK-based flag evaluation adds no network call per evaluation and fires a tracking callback on each assignment exposure — meaning every time a user is assigned to a provider variant, your code logs that event to your data warehouse. That log entry is what connects "this user was assigned to Anthropic" with "this user completed their task three minutes later" when you run your analysis. Without it, you have inference logs and you have user behavior logs, but no reliable way to link them.
Sequential testing, which lets you call a winner early if one provider is clearly dominant on cost or latency, is particularly useful for LLM experiments where model versions may change if the experiment runs too long. Prerequisite flags let you gate the provider experiment behind other conditions — for example, running the comparison only for users on a paid tier where the cost difference between providers has meaningful business impact.
The result of this architecture is an experiment that produces the same kind of statistically defensible signal you'd expect from a product A/B test — not a benchmark lookup, not a manual evaluation, but a controlled comparison against the actual user population and tasks that define your product.
The cost-quality trade-off: a 300x price gap that requires experimental validation, not assumptions
The pricing gap between frontier and budget LLMs is not subtle. Claude Opus 4 costs $75 per million output tokens. Llama 4 Scout, available through inference providers, costs $0.25 per million output tokens. That's a 300x difference. Whether that gap is justified depends entirely on what you're asking the model to do — and the only reliable way to know is to run an experiment, not to assume.
The pricing landscape: a 300x gap that keeps widening
The full spectrum of LLM pricing today runs from roughly $0.07 per million input tokens at the budget floor to $75 per million output tokens at the frontier ceiling. Within that range, there are meaningful tiers. Claude Sonnet 4 sits at $3/$15 per million tokens. GPT-4.1 comes in at $2/$8. Gemini 2.5 Flash at $0.15/$0.60 represents strong mid-tier value. GPT-4.1 nano, explicitly positioned for high-volume latency-sensitive workloads, matches Llama 4 Scout at $0.10/$0.40.
The token economics described earlier become even more complex at the endpoint level. As one engineer at OpenRouter noted in a practitioner discussion, "the right lens is actually the price per token by endpoint, not by model" — because thinking modes, caching discounts, fast versus slow endpoints, and prompt-length-dependent pricing all affect what you actually pay.
A team that benchmarks Claude Opus 4 against Llama 4 Scout on headline price but ignores caching behavior may be comparing the wrong numbers.
That 6-point gap sounds modest until you consider what it represents at the tail of the distribution — the hard cases, the edge inputs, the prompts where a wrong answer has real consequences.
A task-stakes framework for model selection
The right way to think about model selection is across two axes: the stakes of a wrong answer, and the volume of requests you're running.
High-stakes, lower-volume tasks — legal contract review, medical triage, complex multi-step code generation, financial analysis — are where frontier models earn their premium. If a model error produces a materially wrong legal interpretation or a missed diagnosis, the $75/M output cost is a rounding error compared to the downstream risk. This is the quadrant where Claude Opus 4 or GPT-4.1 is the rational choice.
High-volume, low-stakes tasks — webpage summarization, content tagging, classification, FAQ responses — are where frontier pricing becomes economically unsustainable at scale. Running a million summarization requests per day through Claude Opus 4 costs $75,000 in output tokens alone. The same workload on Llama 4 Scout costs $250. If the quality difference doesn't produce a measurable difference in user outcomes, you're paying 300x for nothing.
The middle tier — GPT-4.1 mini, Gemini 2.5 Flash, Claude Haiku 3.5 — handles the large category of medium-stakes tasks where you need reliable performance but can't justify frontier pricing at volume. GPT-4.1 mini cuts cost by roughly 80% compared to GPT-4.1 with surprisingly small quality tradeoffs on structured tasks, making it a strong default for most product-facing workloads.
Volume discounts, committed-use agreements, and batch processing can reduce costs by 25–50% depending on the provider, which shifts the math further toward mid-tier and budget models for predictable workloads.
Validating the trade-off with downstream business metrics
The framework above gives you a starting hypothesis. Experiment data is what confirms or overturns it.
The right validation question isn't "which model scores higher on our internal eval?" It's "does the quality difference between models produce a measurable difference in the business metric we actually care about?" For a summarization feature, if users engage equally with Llama 4 Scout output and Claude Opus 4 output, the 300x cost premium is unjustified — full stop. For a legal review workflow, if error rates or user correction rates differ meaningfully between models, the premium is justified.
This is where the experiment infrastructure described earlier closes the loop. A warehouse-native experiment platform with read-only data access lets you join inference cost data with downstream user outcome metrics in a single pipeline — without routing sensitive data through a third party.
Metric correlation analysis is particularly useful here: it surfaces whether an experiment that reduces cost also moves retention, task completion, or purchase rate, making the trade-off empirically visible rather than assumed.
Pricing data changes frequently — the figures cited here reflect mid-2026 rates, and inference costs have been falling. That trajectory reinforces the case for running experiments now rather than waiting for the market to stabilize. The model that's 10x cheaper than the frontier today may be 2x cheaper in six months, which changes the math on every cost-quality decision you've already made.
From experiment results to provider strategy: gradual rollouts, fallbacks, and multi-provider routing
Running a controlled experiment to compare OpenAI, Anthropic, and open-source alternatives gets you to a decision. But the decision itself — "Anthropic wins on quality, let's ship it" — is only the beginning of the work.
How you move traffic to the winning provider, what happens when that provider has an outage at 2am, and whether you eventually route different task types to different providers: these are the infrastructure questions that determine whether your experiment results translate into durable production value or a one-time configuration change that nobody touches again.
Gradual traffic shifting with guardrail metrics
The instinct after a clean experiment result is to cut over completely. Resist it. A controlled experiment runs on a sample of your traffic under specific conditions — it won't surface every edge case that emerges at full scale. A gradual rollout (5% → 25% → 50% → 100%) gives you the observability window to catch problems before they affect your entire user base.
What makes a gradual rollout safe is guardrail metrics — specific thresholds that trigger a rollback automatically if breached during ramp-up. For an LLM provider migration, your guardrails should cover at minimum: error rate, p95 latency, cost per request, and a user satisfaction signal.
If your new Anthropic integration starts returning 5xx errors at 3% of requests during a 10% rollout, a guardrail on error rate should halt the ramp and route traffic back to OpenAI before the problem scales. Statistical guardrails formalize this pattern with dedicated guardrail metrics in the analysis settings, separate from primary and secondary metrics, with configurable risk thresholds — which means the rollback logic is part of the experiment definition, not an afterthought in a runbook.
Token counts can also spike unexpectedly with certain prompt patterns or user inputs at scale — a cost-per-request guardrail will surface this before it becomes a budget problem.
Handling provider outages and fallback logic
Single-provider dependency is a production risk that's easy to underestimate until it materializes. In October 2025, a major infrastructure outage affected roughly 99% of server-side SDKs globally for approximately 24 hours — a concrete illustration of what cascading failure looks like when infrastructure depends on a single external service without fallback logic.
The same failure mode applies to LLM providers: if your application routes all inference through one provider and that provider goes down, you need a path that doesn't require a code deploy to recover.
The fallback architecture is straightforward in principle: primary provider → secondary provider → cached response or graceful degradation. The operational challenge is making the switch fast enough to matter.
Feature flag kill switches solve this — the ability to instantly deactivate a provider variant and route to a fallback without touching application code. When the flag evaluation happens locally from a cached payload rather than via a network call to an external flag service, the fallback mechanism doesn't inherit the same availability risk as the provider it's protecting against.
Multi-provider routing as the mature end state
The most sophisticated teams don't pick a single winning provider and stop there. They route different task types to different providers within a single workflow — a cheap open-source model handling intent classification or content moderation, a frontier model handling final response generation where quality directly affects user experience.
This architecture reflects a straightforward economic reality: paying frontier model prices for every inference step in a pipeline is unnecessary when many of those steps are low-stakes and high-volume.
The routing logic lives in feature flags rather than application code, which means you can adjust which provider handles which task type without a deployment. Feature flags support attribute-based targeting rules, so you can route specific user segments or request types to specific providers, and kill switches allow instant cutover if a provider degrades. This also provides natural redundancy: if one provider degrades, you can shift its traffic to another via a flag update.
Character.AI uses GrowthBook to "compare different modeling techniques from the perspective of our users," which is exactly this kind of ongoing, production-integrated routing optimization rather than a one-time benchmark exercise. That kind of continuous routing optimization is only sustainable when the flag system, the experiment analysis, and the metrics all live in the same platform — which is the unified architecture the warehouse-native approach described earlier is designed to support.
The feature flag system that ran your experiment should also run production routing
The feature flag system that managed your initial experiment should also manage the production routing that follows from it. When the routing decisions and the experiment results that informed them live in the same platform, you eliminate the data pipeline complexity of reconciling a flag management tool with a separate analytics layer.
Practically, this means using the same targeting and rollout controls for provider routing that you used for the experiment itself: environment-scoped flags for staged rollouts, kill switches for emergency cutover, and attribute-based targeting to route specific user segments or request types to specific providers. The experiment was a temporary measurement instrument; the feature flag is the permanent control plane. Treating them as the same infrastructure — rather than separate tools that need to be kept in sync — is what makes provider strategy manageable as your LLM usage scales.
Turning experiment results into a provider strategy you can actually maintain
The through-line of this article is simple: LLM provider decisions made from benchmarks are guesses dressed up as analysis. The only way to know which provider performs better on your product is to measure it on your users, with your prompts, against outcomes that actually matter to your business. Everything else — the leaderboard rankings, the pricing comparisons, the vibes-based evaluations — is useful for narrowing the field, not for making the call.
Pick one feature, two providers, and a primary metric before you write any instrumentation code
The teams that get stuck are usually the ones trying to compare everything at once. Pick one LLM-powered feature where you have enough traffic to reach statistical significance in a reasonable timeframe, and define two or three metrics before you write a line of instrumentation code.
Quality and latency are almost always on that list; cost becomes the third metric once you have a quality baseline you're satisfied with. A focused first experiment — one feature, two providers, a clear primary metric — teaches you more about your measurement infrastructure than any amount of planning does.
Multi-provider routing is where you end up after experiments, not where you start
Multi-provider routing isn't a starting point — it's where you end up after you've run enough experiments to know which task types actually benefit from frontier model quality and which don't. The task-stakes framework from the cost section gives you the hypothesis; your experiment results give you the evidence.
Start routing different task types to different providers only after you have data showing that the quality difference between models produces a measurable difference in user outcomes for that specific task. Otherwise you're adding operational complexity without a business case.
Three infrastructure prerequisites that determine whether your experiment data is trustworthy
Three things need to be in place before your first experiment produces trustworthy results: a way to route traffic without code deploys, a place to join inference logs with user outcome events, and guardrail thresholds defined before the experiment runs — not after you've seen the data.
A warehouse-native experiment approach handles the second and third together, letting you define guardrail metrics in the same framework as your primary metrics and query everything against your own data warehouse. The feature flag system that routes your experiment traffic should be the same system that manages production routing after you've called a winner.
This article is meant to give you a complete, usable process — not just a framework to think about. If it saves you from a vibes-based evaluation or a benchmark lookup that leads you to the wrong provider, it's done its job.
What to do next: Identify one LLM-powered feature in your product that has measurable user outcomes — task completion, satisfaction rating, return visits, anything quantifiable. Define your primary metric and one guardrail metric. Then run an A/A test to confirm your instrumentation is working before you introduce a real provider difference. That's the whole first step. Everything else in this article follows from having clean data to work with.
Related insights
Related Articles
A magazine's home page shows two recent issues. The design team wants subscribers to try a shelf with four. All four covers are public, and changing editions while the page is open should update the shelf immediately. That gives you a small React feature with a useful acceptance test. Click from guest to subscriber and back, and count the covers each time.
We'll put the display limit in a typed local flag, evaluate it inside a React component, and leave the choice of edition with the app. The example runs in a client-rendered React app without a GrowthBook account, an SDK key, or a request for flag rules. For the wider workflow, free feature flags for coding agents explains what to ask an agent to implement and how to review the result.
Define what one flag controls
Start with an existing React and TypeScript app, or create a Vite React project for the example. Install both GrowthBook packages so the definitions and the hooks resolve against compatible SDK versions.
Create src/flags.ts. Here the feature value is a number, which lets the component use the same rendering code for either edition. A future change from four covers to three is one edit to the rule.
A guest falls through to the default of two. A subscriber matches the rule and gets four. This rule applies to every subscriber, so the ID has no effect on the result here. If you later roll the shelf out to a percentage of subscribers, you already have an identity to use for repeatable assignment.
The type registration release note explains the version requirement for LocalFeatures. The registration connects the definition, the attributes, and the value returned by the hook. For the TypeScript mechanics, see Jeremy Dorn's Register pattern walkthrough.
Put the current reader above the shelf
Replace src/App.tsx with the component below. The edition switch is a local fixture so anyone reviewing the change can reproduce both states. In an existing app, take those two values from the active reader in your session layer.
The provider receives an instance initialized with the current reader and the checked-in rules. React can render the correct shelf on the first pass for that reader. If the app is still loading a session, decide what should occupy the shelf in the meantime. For this public list a two-cover guest view is reasonable. On a page where a switch would interrupt the reader, wait for the session before mounting the shelf.
Give your agent the React setup
Use the local flags guide to ask for a typed definition, a provider with the current reader, and a test that changes the edition.
Open the Agent GuideThe useMemo dependencies include the ID and the edition. If a reader subscribes while signed in, their ID can stay the same while their edition changes. Depending only on the ID would leave the old SDK instance in place. Passing a fresh object as the dependency on every render would create unnecessary instances. The example uses the two primitive values the rule setup actually needs.
Read the numeric flag where React renders the list
Create src/IssueShelf.tsx. Keep one stable ID per issue and let the component use the resolved value to select how many items to render.
Keep the hook at the top of the component, inside the provider's subtree. The React SDK supplies the flag value through that provider. Calling a hook inside a click handler or inside the list loop would break the Rules of Hooks. Use the returned number in ordinary render logic.
There are two places you can see the number two in this implementation. The definition's defaultValue is what an ordinary guest gets through evaluation. The 2 passed to the hook is a fallback for a value the SDK can't supply. Giving them the same value makes the basic shelf a sensible fallback, but checking only the guest case would let a broken provider arrangement or missing definition go unnoticed. The subscriber case proves that the component actually received the rule.
The list keys identify magazine issues. Keep those keys independent of the flag. Switching from two covers to four should preserve the identity of the first two rows. There's also no need to remount the whole app with an edition-specific key. React preserves state according to component position and keys. For example, a search input outside the shelf shouldn't lose its text because someone subscribed.
Check the transition in both directions
Use the template's build script to type-check and bundle the app. Once that passes, start the dev server and open the local address it prints.
On first load, the page says guest and lists November and October. Click Switch edition. The same page should say subscriber and add September and August. Click again. The list should return to the original two issues, in order. This last check catches code that appends more results on upgrade and never removes them on downgrade.
For a compile-time check, temporarily replace the numeric fallback with the string "2". Run the build again and inspect the error on the hook call. Then restore 2 and rebuild. If the string compiles, check that src/flags.ts belongs to the same TypeScript project as the component and that the package manager resolved compatible core and React versions.
Look for the core package used by your app and by the wrapper. If the app has several incompatible installations, align the versions before diagnosing the JSX. A team using an existing build script should also confirm it actually runs the TypeScript checker.
Hand off a React change someone can review
Give your coding agent the one-shot local feature flags guide and a short description of the observable behavior. For this shelf, the request can be as specific as the test.
The shelf controls how many public titles to display. If your actual feature unlocks paid articles, enforce access when the server serves an article. A client-rendered flag only decides what to show in that browser. Whenever a change to the display limit can wait for a deployment, the small local file keeps the decision reviewable alongside the component. When an editor needs to change it between issues without an engineering release, compare the free GrowthBook options for managing flag rules.
Manage the shelf in GrowthBook
Start a GrowthBook workspace when your magazine team is ready to manage shelf rules between deployments.
Get Started with GrowthBookTwo customers download the same weekly report. One has agreed to preview a new CSV column. The other feeds the old two-column format into an importer. Both requests can land on the same Node.js process, and each needs the right file even if the other request arrives while the report is loading.
This tutorial builds that endpoint with one checked-in feature flag. The process loads the rules once. Each request supplies its own workspace attributes and receives its own evaluation. You can run the whole example on your machine without an account, a client key, or a flag server. The free feature flags for coding agents walkthrough introduces the local approach. Here we'll give the agent a server-specific test to pass.
Set up a small TypeScript service
Use Node.js 22 or newer for this example. In an empty directory, create an npm project that uses ES modules, install the core SDK, and add the TypeScript tools.
Create tsconfig.json at the project root. The sample runs TypeScript directly with tsx and checks types in a separate step. Type checking with tsx explains why the two commands serve different purposes.
The following files all live next to that configuration. The server imports ./flags.js even though the source file is flags.ts. That spelling follows TypeScript's Node.js module resolution for ESM and works with this runner.
Define the report contract in one flag
Create flags.ts. The public format has two columns. The sample preview workspace gets one additional column. The only targeting attribute the rule needs today is reportPreview. Carry the workspace ID too, so two people downloading a report on behalf of the same workspace can share an assignment if you introduce a percentage rollout later.
The SDK type registration update covers this rule syntax and the 2.2.0 minimum. If you misspell reportPreview in a condition or use a string where the boolean flag expects a value, TypeScript can point at the definition. The Register pattern also makes the same feature name available in other modules without threading a generic type through each handler.
Before you add the endpoint, decide what belongs to the process and what belongs to the request. The feature definitions are identical for both customers. Their identity and preview enrollment can differ. If a handler changes an attribute on a single shared user instance before awaiting a database query, another handler could replace that attribute before the first handler resumes.
Give your agent a server-side task
Use the one-shot guide to add checked-in rules. Ask your agent to keep workspace attributes local to each request and demonstrate both CSV formats.
Open the Local Flags GuideCreate a scope when the request arrives
Create server.ts. The Node.js SDK provides GrowthBookClient for the process and createScopedInstance for the current request. The two fixture paths below stand in for two authenticated workspaces. The server binds to the loopback address so you can exercise it locally.
The HTTP handler looks up a workspace, creates its scope, and holds that scope across an asynchronous operation. The short promise-based timer gives a second request time to arrive. In a real export, that's where the database or storage read would happen. Keep the stable client at module scope and the scoped instance inside the handler. If a formatter needs the decision, pass it the boolean or the scoped instance.
In production, resolve the workspace and its access rights from the authenticated session before reading the report. The two selectable paths here are fixtures for public sample data. A caller's choice of a header, query string, or workspace slug can't establish permission to read another customer's report. The endpoint also prevents shared response caching. If you cache real exports, the cache needs to distinguish the workspace and the report format, along with any other inputs that change the response.
Test two requests that overlap
In the first terminal, type-check the service and start it. A successful type check exits quietly. The next command prints the loopback address and keeps the server running.
Save the following as verify.mjs. In a second terminal, run node verify.mjs. Node's built-in fetch calls the local server. Strict assertions compare the full header and data row, including where each row ends.
You should see the single success line. Testing just the preview workspace proves that the code can add a column. Testing both responses catches the more expensive mistake of silently changing an existing customer's export. Keeping the old format assertion around is especially valuable when the downstream importer belongs to someone outside your team.
To check the compile-time boundary, temporarily change gb.isOn("includeUniqueReaders") to gb.isOn("includeUniqueReader") and rerun npx tsc --noEmit. The diagnostic should identify the misspelled key. Restore it before running the server again. A coding agent can include the before-and-after type check and the two CSV headers in its pull request.
Decide when to expand the report
When one preview customer is ready, leave everyone else on the default. If the next step is to enroll a fraction of workspaces, choose an attribute that matches the promise you're making. Hashing a workspace ID lets colleagues downloading the same report share a format. Hashing each user's ID could give two analysts in the same company different column sets. The one-shot guide shows how to express a percentage and hash attribute in a local rule.
A new rule in flags.ts reaches a process through your deployment. During a rolling deploy, the same workspace might hit old and new processes. If customers need a durable choice of export schema, keep supporting the agreed format in the API itself. When the operational requirement is to change targeting between deploys, you can keep the scoped evaluation in the handler and change how the process receives its rules. The free GrowthBook offerings overview covers Cloud Starter and self-hosting for teams that want to manage those rules.
Manage report targeting in Cloud
Create a GrowthBook workspace when the team supporting exports needs to expand the preview independently of a server release.
Get Started with GrowthBookYour conference agenda has a new “Show room” button. Reviewers should see it on the first page load. Everyone else should get the existing agenda. If a Server Component renders the old agenda and a browser hook independently decides to show the new button, the first HTML and the browser can disagree.
In the Next.js App Router, the server can make this decision once and pass a boolean to the interactive component. We'll define the flag in the repo, select the preview audience with a local test cookie, and verify the actual HTML for both visitors. Clicking the button will still work after hydration. You can follow along without a GrowthBook account or client key. If you're assigning this work to an agent, the free feature flags for coding agents walkthrough gives the background.
Keep the flag definitions on the server
Use a TypeScript App Router project, or create a small one with create-next-app. These paths assume the project has an app directory at its root. If yours uses src/app, put both app and lib under src so the relative imports still match.
Keep the starter's root layout. Create lib/agenda-flags.ts with the following code. The SDK type registration update explains how LocalFeatures checks the flag and its rule against the registered types. This setup requires version 2.2.0 or later.
The module can reuse the client and rules across requests handled by the same process. It only holds the current visitor's audience inside the function call. Two requests can therefore use the same flag file and get different results. The Node.js SDK documents the scoped client used under the App Router here.
This particular rule has no percentage and needs no visitor ID. The two audiences are sufficient. If the team later asks for a rollout to 10% of attendees, add a stable attendee or registration ID and choose which of those units should stay together. Jeremy Dorn's Register pattern article explains how a change to an attribute type reaches the call sites that construct it.
Read the cookie for this request
Create app/agenda/page.tsx. The static heading can render for everyone. The request-specific content sits behind a Suspense boundary, so the fallback can show a neutral loading message until the server has the cookie.
The App Router's cookies function reads the incoming request asynchronously. Read it inside the visitor-specific component. Keeping that read out of shared cached code lets the surrounding page reuse common content without treating one visitor's decision as another's. This placement also accommodates App Router projects using Cache Components.
Give your agent the Next.js setup
Use the local flags guide with a concrete request to evaluate one flag on the server and return the same decision to the browser.
Open the Local Flags GuideThe cookie in this demo is a convenient way to preview a public UI treatment. Anyone with that cookie can see the room label. To target paying attendees or private sessions, obtain the audience from the verified session on the server and authorize the underlying data separately.
Pass one decision to the interactive component
Create app/agenda/Agenda.tsx. It's a Client Component because a visitor can open and close the room details. Its initial branch comes directly from the boolean supplied by the page.
The client boundary takes a serializable prop. The component receives true or false. The SDK instance, targeting rules, and cookie handling stay in the server module. You don't need a React provider for this component because its only browser-side choice is whether the visitor has clicked the button.
Follow one page load through server rendering and hydration. For a preview visitor, the server can send a section with a “Show room” button. React's first client render gets the same showRoom value and starts with open set to false. Hydration attaches the click handler. Opening the room detail then updates component state and doesn't require another flag evaluation.
Verify the HTML and the click separately
Build the production app and start it on port 3100.
In a second terminal, save this as verify-agenda.mjs in the project root and run node verify-agenda.mjs. The test makes two requests to the same route and looks for a marker on the rendered section. A marker in the HTML helps catch an implementation that only adds the intended layout after JavaScript runs.
Now open http://localhost:3100/agenda in a fresh browser profile. You should see the session title without a room button. In that local page's browser console, set the demo cookie and reload.
Click Show room and look for Room 204. Click Hide room and the room should disappear. This second check proves the component became interactive. If the server response test passes but the click fails, inspect the browser console for a hydration error before changing the flag rules.
Remove the fixture and reload once more. The button should disappear and the agenda title should remain.
The reload is deliberate. Editing the cookie in an already open document doesn't rerun its Server Component. In your app, use the normal session-change flow to request a fresh server render when a visitor signs in, signs out, or leaves a preview group.
Choose where the next flag should be evaluated
For a decision needed in the initial HTML, give the agent an observable requirement. Ask it to show the two HTTP responses, then click the interactive control in the preview. The first check catches an incorrect layout. The second catches correct HTML that never becomes interactive.
If a later feature depends on an action entirely within the browser, evaluate whether its flag belongs in the client tree. The one-shot local flags guide covers both placements. This agenda only needs one server decision. Updating its checked-in rule takes a deployment. Keep that tradeoff in view if the event organizer needs to pause a preview while attendees are already arriving. For that case, compare GrowthBook’s free options for changing flags between deploys.
Manage the agenda rollout in Cloud
Create a GrowthBook workspace when the organizer needs to adjust a preview audience while your Next.js app is serving attendees.
Get Started with GrowthBookReady to ship faster?
No credit card required. Start with feature flags, experimentation, and product analytics—free.



