Try Bifrost Enterprise free for 14 days.Try Bifrost Enterprise free for 14 days.

Request access

Fine-Tuning vs Prompt Engineering: When to Fine-Tune an LLM

Fine-tuning vs prompt engineering is a choice between changing a model's weights and changing what each request sends. This guide compares cost and benefit with a decision table, current vendor pricing, break-even math, and a method for measuring ROI at the gateway.

Fine-Tuning vs Prompt Engineering: When to Fine-Tune an LLM

TL;DR

  • Fine-tuning vs prompt engineering is a choice between changing model weights with labeled training data and changing the instructions and examples sent with each request, so the two cost money in different places.
  • RAG fixes missing or stale knowledge, prompt engineering fixes most behavior problems, and fine-tuning is the right lever only when behavior stays inconsistent after prompting and a labeled dataset of 50 or more quality examples exists.
  • On OpenAI's published rates, a fine-tuned gpt-4.1-mini costs twice the base model per input and output token, so fine-tuning saves money mainly when it lets a smaller model replace a larger one, not when it only shortens the prompt.
  • Fine-tuned models carry costs prompts do not: hosting or storage fees on some platforms, retraining, and retirement when the base model is deprecated.
  • Bifrost does not train or host models; it routes traffic to base and fine-tuned models, prices each request through model aliases and pricing overrides, and records tokens and cost per request.

Fine-tuning vs prompt engineering is a choice between changing a model's weights with labeled training data and changing the instructions, examples, and context sent with every request. Both can fix the same failing output, but they shift cost to different places: fine-tuning moves spend into training, hosting, and maintenance, while prompt engineering moves it into input tokens on every call. Bifrost, the open-source AI gateway built in Go by Maxim AI, sits on the request path to both kinds of model and records the token usage and cost needed to compare them. This guide covers when each approach wins, where RAG fits, what each costs in 2026, and how to measure the return on a fine-tune.

What Is Fine-Tuning, and How Is It Different from Prompt Engineering?

Fine-tuning is the process of continuing a pretrained model's training on a smaller, task-specific dataset so its weights encode a behavior, format, or style. Prompt engineering leaves the weights unchanged and shapes output through the instructions, examples, and constraints sent with each request.

A short definition of fine-tuning covers the training mechanics; here, the operational differences matter more:

  • Prompt engineering covers system instructions, few-shot prompting, output schemas, and step-by-step decomposition. It works on any model, and a change ships as fast as a config edit.
  • Fine-tuning includes supervised fine-tuning on input and output pairs, preference tuning, and parameter-efficient methods such as LoRA. It produces a new model ID tied to its base model.
  • Retrieval-augmented generation (RAG) retrieves documents at request time and inserts them into the prompt, changing what the model knows for that request without changing the model.
Application request passes through prompt engineering and RAG context layers to the model, while an offline fine-tuning job updates the model weights

Application request passes through prompt engineering and RAG context layers to the model, while an offline fine-tuning job updates the model weights

Figure 1: Prompt engineering and RAG act on every request at run time, while fine-tuning acts once, offline, on the model itself.

As Figure 1 shows, two levers act on the request and one acts on the model, which explains most of the cost differences below. For a deeper treatment of the request-side techniques, see this guide to prompt engineering for AI teams.

Fine-Tuning vs Prompt Engineering vs RAG: Decision Table

The fine-tuning vs prompt engineering decision, with RAG as the third option, comes down to six attributes: labeled data needed, upfront cost, cost added to each request, latency, upkeep, and which failure each fixes. The table below compares them.

Attribute Prompt engineering RAG Fine-tuning
Data needed A few examples and an eval set A document corpus and an index 50+ labeled examples to start, often far more
Upfront cost Engineering time only Embedding, indexing, retrieval infrastructure Dataset curation, training job (tokens x epochs), evals
Per-token inference cost Base rates; long prompts add input tokens to every call Base rates plus retrieved context tokens Fine-tuned rates, sometimes above base rates; shorter prompts
Latency Grows with prompt length Adds a retrieval step Shorter prompts or a smaller tuned model can be faster
Maintenance Edit and version prompts Keep the index fresh Retrain on new data; migrate when the base model is retired
Fixes Instructions, format, tone, most task behavior Missing, private, or stale knowledge Consistency the prompt cannot enforce, cost at high volume
Wins when Requirements change often or volume is modest Answers depend on facts that change Behavior is stable, volume is high, and a labeled dataset exists

Prompt engineering is the default because it has the lowest upfront cost and the fastest iteration loop. Fine-tuning earns its place when a stable, high-volume task repays training and upkeep. These tradeoffs sit inside the broader practice of LLM cost optimization, where model choice, caching, and routing are weighed together.

Whichever column a team picks, per-request costs land in the traffic between the application and the provider, which makes a gateway such as the Bifrost LLM gateway a practical place to compare them.

RAG vs Fine-Tuning: Knowledge Gaps vs Behavior Gaps

RAG vs fine-tuning is the most common version of this decision, and the way to settle it is to classify the failure first. If the model lacks facts, the fix is RAG. If it has the facts but applies them inconsistently, formats output wrongly, or drifts in tone, the fix is prompt engineering first and fine-tuning second.

Fine-tuning is a poor way to add knowledge: facts baked into weights go stale when the source data changes, and refreshing them means another training run. RAG keeps knowledge in an index that updates in minutes and can show which document an answer came from.

Fine-tuning is a strong way to enforce behavior. A model trained on a few hundred examples of the exact output schema or label set follows it more consistently than a model reading the same rules from a long system prompt. The techniques also stack: production systems often fine-tune for format and use RAG for facts. The architecture and failure modes of RAG pipelines are covered in a separate guide.

What Fine-Tuning an LLM Costs in 2026

Fine-tuning an LLM has three cost layers: a one-time training charge, an optional fixed charge for hosting or storing the custom model, and a per-token inference charge that may differ from the base model's rate. Vendors combine these layers differently, so the same fine-tune costs different amounts on different platforms.

The structures below come from vendor pricing pages read on December 3, 2026. Prices change often, so check the current page before budgeting.

Platform Training billed as Fine-tuned inference billed as Fixed charges
OpenAI API Per 1M training tokens (gpt-4.1-mini: $5.00) Fine-tuned rates (gpt-4.1-mini: $0.80 input, $3.20 output per 1M tokens, vs $0.40 and $1.60 for the base model) None listed for SFT inference
Microsoft Foundry (Azure OpenAI) Training tokens x epochs x training rate for SFT and DPO; training hours for RFT Base-model token rates on Standard and Global Standard deployments Hourly hosting fee per fine-tuned deployment; Developer deployments have none but are removed after 24 hours
Amazon Bedrock Per 1M tokens trained (corpus tokens x epochs) Per model unit per hour under Provisioned Throughput; custom Nova on-demand at base Nova rates Monthly storage fee per custom model

Sources: the OpenAI API pricing page, Microsoft's guide to managing fine-tuning costs in Foundry, and Amazon Bedrock pricing.

Fine-tuning cost lifecycle from dataset preparation and a training job billed by tokens times epochs, to hosting or storage fees billed by time, to per-token inference recorded in Bifrost logs

Fine-tuning cost lifecycle from dataset preparation and a training job billed by tokens times epochs, to hosting or storage fees billed by time, to per-token inference recorded in Bifrost logs

Figure 2: Only per-request inference passes through the gateway, so a full ROI view adds training and hosting charges from the provider invoice.

Two lifecycle facts belong in any fine-tuning budget. OpenAI is closing self-serve fine-tuning: its deprecations page states that no organization can create new self-serve fine-tuning jobs from December 15, 2026, and that existing fine-tuned models keep serving until their base model is retired. The same page lists January 14, 2027 shutdowns for gpt-4o-mini, gpt-4.1, and gpt-4.1-mini, which are common fine-tuning bases.

A fine-tune is a dated asset, and its replacement cost belongs in the ROI calculation. New fine-tunes will run on other platforms, such as Bedrock, Foundry, Vertex AI, or open-weight models served with vLLM. Bifrost reaches 10,000+ models across 35+ providers through one OpenAI-compatible API, so moving between them needs no client changes.

The Token Cost of Prompt Engineering, and the Break-Even Math

Prompt engineering has no training bill, but every instruction and few-shot example in the prompt is billed as input tokens on every request. A fine-tune can shrink that prompt, yet on platforms that charge a premium for fine-tuned inference, a shorter prompt does not always produce a cheaper request.

The worked example below uses the OpenAI rates above for one million requests, each with 500 tokens of user content and 300 output tokens. The prompt-engineered version adds a 2,000-token system prompt; the fine-tuned version uses a 200-token prompt.

Setup Input tokens per request Cost per request Cost per 1M requests
Base gpt-4.1 with 2,000-token prompt 2,500 $0.0074 $7,400
Base gpt-4.1-mini with 2,000-token prompt 2,500 $0.00148 $1,480
Base gpt-4.1-mini, static prompt billed at cached-input rate 2,500 (2,000 cached) $0.00088 $880
Fine-tuned gpt-4.1-mini with 200-token prompt 700 $0.00152 $1,520

The arithmetic shows three things:

  • Shortening the prompt alone did not pay. The fine-tuned mini model costs slightly more per request than the base mini model, because the 2x output rate outweighs the 1,800 input tokens saved.
  • Prompt caching widens the gap. With the static prefix served from the provider's prompt cache, the prompt-engineered base model is the cheapest row. Bifrost can add cache breakpoints for clients that send none through auto prompt caching.
  • The saving comes from model downsizing. If fine-tuning lets gpt-4.1-mini match gpt-4.1's quality on the task, cost per request drops by about 4.9x. A training run of 1M tokens for 3 epochs at $5.00 per 1M tokens costs $15, recovered after roughly 2,550 requests at the gpt-4.1 rate.

The training bill is rarely the expensive part; dataset curation, evaluation runs, retraining, and migration cost more and never appear in a per-token price. The Bifrost LLM cost calculator helps run the same arithmetic for other models, and this guide to cutting AI spending without losing quality covers the prompt-side levers that compete with a fine-tune.

When to Fine-Tune an LLM, and When Prompt Engineering Wins

Fine-tune an LLM when four conditions hold: the failure is about behavior rather than knowledge, prompt changes have stopped improving eval scores, at least 50 quality labeled examples exist, and the task is stable and high-volume enough for savings to repay training and upkeep. Otherwise, prompt engineering or RAG is the better investment. The 50-example floor follows OpenAI's guide to optimizing LLM accuracy, which recommends starting fine-tunes at 50+ quality examples and establishing a prompt-engineering baseline first.

Decision flow: missing facts lead to RAG, prompt-fixable issues ship as prompt engineering, and only failures with 50+ quality examples lead to fine-tuning

Decision flow: missing facts lead to RAG, prompt-fixable issues ship as prompt engineering, and only failures with 50+ quality examples lead to fine-tuning

Figure 3: Fine-tuning is the last branch, reached only after RAG and prompting fail and a labeled dataset exists.

Prompt engineering wins in these cases:

  • Requirements change often. A prompt edit ships in minutes; a fine-tune needs new data, training, and evals.
  • Volume is modest. At low request counts, long-prompt token overhead is small next to the cost of a training pipeline.
  • Model portability matters. A prompt moves to a newer base model with light rework; a fine-tune retires with its base model.
  • The team lacks labeled data. Without representative examples, a fine-tune learns the wrong distribution.

Fine-tuning wins in these cases:

  • Strict output contracts. Classification labels, extraction schemas, or house style that a prompt enforces only most of the time.
  • Downsizing at high volume. A fine-tuned small model replacing a large base model on a narrow task, the main cost lever in the break-even table.
  • Prompt bloat. Prompts long enough to add latency and input cost on every call, on platforms that bill fine-tuned inference at base rates.

Teams still building their prompt practice can start with this practitioner's guide to prompt engineering. Bifrost keeps prompt changes measurable as well: the prompts plugin applies committed prompt versions from the Prompt Repository by header, and each log records the prompt name and version used.

How Bifrost Tracks Costs Across Base and Fine-Tuned Models

Bifrost prices every request it routes by matching the model against its Model Catalog and any pricing overrides, then records tokens, cost, and latency in its logs. Fine-tuned models need one extra step because a fine-tune ID has no catalog row, so a model alias and a pricing override map it to the correct rates.

The pieces work as follows:

  • Model aliases. A static alias on a provider key maps a stable name the application sends, such as support-model, to a model_id that can be a deployment name, an inference profile ARN, or a fine-tuned model ID. An optional model_name sets the canonical name used for pricing and logs. On Vertex AI, an alias for a fine-tuned model also sets its project_number.
  • Model Catalog. The Model Catalog syncs a pricing datasheet every 24 hours and calculates cost per request. When no pricing exists for a model, the calculated cost is 0.
  • Pricing overrides. Custom pricing sets input and output token rates for an exact model name or a wildcard prefix, scoped globally or to a provider, provider key, virtual key, or user. Overrides match the wire model, so an override on a fine-tune ID applies whichever alias sent the request. Providers that return their own usage.cost are priced from that figure instead.
  • Routing info. Every response carries a routing_info block (also sent as x-bifrost-routing-info-* headers) showing the requested model and the resolved model_id.
Request with a virtual key passes through Bifrost, where an alias resolves the fine-tuned model ID and a pricing override turns token usage into logged cost

Request with a virtual key passes through Bifrost, where an alias resolves the fine-tuned model ID and a pricing override turns token usage into logged cost

Figure 4: A fine-tuned model ID has no catalog row, so a pricing override is what turns its token counts into a cost.

The right setting depends on how the platform bills fine-tuned inference. On OpenAI, fine-tuned rates differ from base rates, so the fine-tune ID gets its own override:

{
  "providers": {
    "openai": {
      "keys": [
        {
          "value": "env.OPENAI_API_KEY",
          "models": ["*"],
          "aliases": {
            "support-model": {
              "model_id": "ft:gpt-4.1-mini-2025-04-14:acme::abc123"
            }
          }
        }
      ]
    }
  },
  "governance": {
    "pricing_overrides": [
      {
        "id": "7f3e2a10-0000-4000-8000-000000000001",
        "name": "Fine-tuned gpt-4.1-mini rates",
        "scope_kind": "provider",
        "provider_id": "openai",
        "match_type": "wildcard",
        "pattern": "ft:gpt-4.1-mini-2025-04-14*",
        "request_types": ["chat_completion", "responses"],
        "pricing_patch": "{\"input_cost_per_token\":0.0000008,\"output_cost_per_token\":0.0000032}"
      }
    ]
  }
}

On Microsoft Foundry, fine-tuned Standard deployments are billed at base-model token rates, so setting the alias model_name to the base model lets the catalog price the opaque deployment name; the hosting fee comes from the invoice. On Bedrock Provisioned Throughput, the charge is per model unit per hour, so the request volume Bifrost records becomes the denominator for cost per request.

Because the application calls support-model, retiring the fine-tune means changing the alias target, not client code. Per-model token and spend records appear across the Bifrost observability features, and this walkthrough of tracking LLM token usage across providers and teams covers the reporting side.

Running a Fine-Tuning ROI Comparison Through the Gateway

A fine-tuning ROI comparison needs the same traffic sent to both variants, per-request cost and tokens for each, and quality measured on the same inputs. In the Bifrost gateway, that means splitting traffic with a routing rule, separating spend with virtual keys or log metadata, and reading the results from logs and metrics.

A practical sequence looks like this:

  • Step 1: Split traffic. A routing rule with weighted targets sends a share of requests to the fine-tuned model and the rest to the prompt-engineered base model. Weights sum to 1, and rules can be scoped to one virtual key for a canary.
  • Step 2: Separate the spend. Give each variant its own virtual key with an allowed-models list, or tag requests with an x-bf-lh-experiment header that Bifrost stores in log metadata.
  • Step 3: Cap the experiment. A virtual key budget with a reset duration such as 1d or 1M stops the test from overspending. These budgets and rate limits can also sit at team and customer level.
  • Step 4: Read the numbers. The built-in logs filter by model, provider, time, tokens, and cost, and the logs API returns totals for requests, tokens, cost, and average latency. The Prometheus metrics bifrost_input_tokens_total, bifrost_output_tokens_total, and bifrost_cost_total carry model and provider labels for dashboards.
  • Step 5: Add what the gateway cannot see. Training, hosting, and storage charges come from the provider invoice, amortized over the requests the logs counted.
ROI input Where it comes from What it answers
Cost per request Bifrost logs and bifrost_cost_total Is the fine-tune cheaper per call than the prompt?
Input tokens per request Bifrost logs and bifrost_input_tokens_total How much prompt did the fine-tune remove?
Latency per request Bifrost logs (average latency) Did responses get faster?
Quality per request Eval scores on the same sampled inputs Did the fine-tune hold or improve accuracy?
Training and hosting Provider invoice When do savings repay fixed costs?

The deciding metric is cost per successful request: gateway-recorded variable cost plus amortized fixed cost, divided by requests that passed evaluation. For larger teams, this guide to LLM budget management with hierarchical spend controls shows how budgets nest across teams and customers, and the AI governance capabilities cover access control for both variants. Bifrost's overhead stays under 200 microseconds at 5,000 RPS in published benchmarks, so the measurement layer does not distort the latency comparison.

Frequently Asked Questions

What is the difference between prompt engineering and fine-tuning?

Prompt engineering changes the instructions, examples, and constraints sent to an unchanged model on every request. Fine-tuning changes the model itself by training it on labeled examples, producing a new model ID tied to its base model. Prompt engineering is faster to change and works on any model; fine-tuning enforces behavior more consistently but adds training, hosting, and maintenance costs.

Should I use RAG or fine-tuning?

Use RAG when the model lacks facts, especially private or frequently changing information, because an index updates in minutes and a training run does not. Use fine-tuning when the model has the facts but applies them inconsistently, such as output format or label choice. Many production systems combine both.

How much does it cost to fine-tune an LLM?

Training is usually billed per training token multiplied by epochs, which for small models can be tens of dollars per run. The larger costs come after: fine-tuned inference can carry a per-token premium, some platforms add hosting or storage fees, and data curation, evals, and retraining take engineering time. Check current provider pricing before budgeting.

Is OpenAI fine-tuning still available?

OpenAI's self-serve fine-tuning is closed to new users, and from December 15, 2026, no organization can create new self-serve fine-tuning jobs. Existing fine-tuned models serve until their base models retire; gpt-4o-mini, gpt-4.1, and gpt-4.1-mini are listed for shutdown on January 14, 2027. Bedrock, Microsoft Foundry, and Vertex AI still offer fine-tuning.

Can Bifrost fine-tune models?

No. Bifrost is an AI gateway, not a training or hosting platform. Fine-tuning runs on the model provider's platform or on infrastructure the team operates. Bifrost routes requests to the resulting fine-tuned model through a stable alias, prices them with pricing overrides, enforces virtual key budgets and access policy, and records tokens and cost per request for comparison against base models.

Measure Fine-Tuning vs Prompt Engineering on Real Traffic

The fine-tuning vs prompt engineering decision is a cost and quality question that a spreadsheet can only estimate. Prompt engineering should be the starting point, RAG the fix for knowledge gaps, and fine-tuning the option for stable, high-volume tasks where a labeled dataset can move the work to a smaller model. Routing both variants through the open-source Bifrost gateway gives each request a recorded token count and cost, so the comparison runs on production traffic. Teams that need this across many models and business units can review enterprise deployment options, and to see the cost tracking in practice, book a Bifrost demo.

[ Newsletter ]

Get new articles in your inbox

Guides on AI gateways, LLM infrastructure, and agent evaluation. Unsubscribe anytime.