Why promptfoo runs in CI create unpredictable LLM API spend
Every promptfoo eval that runs in a merge request sends real requests to a model provider, so API spend grows with how often pipelines run and how large the suite is, not with how much the prompts actually changed. promptfoo runs on the machine executing the job and calls the model providers directly, as its documentation describes. That means there is no promptfoo bill to pay: the charges are the provider API fees, billed to the keys your pipeline holds. Those charges land on the team that owns the key, often without anyone deciding how many calls a commit should cost.
Cost controls become necessary in three common situations: pipelines that trigger on every push to every branch, suites that have grown to hundreds of test cases across several providers, and assertions that use an LLM as a judge. A model-graded assertion makes a second model call for each output it grades, so a suite that looks modest on paper can multiply its calls. Red team scans add their own volume, and the Community edition's 10k probes per month limit (promptfoo pricing page) is a different constraint from your provider's spending limit, so do not assume one protects the other.
The rest of this page covers the controls that keep that spend predictable: persisting the response cache between pipelines, running full suites only when prompts change, choosing cheaper grader models and capping concurrency. Before changing anything, confirm with your provider which spending limits, rate limits and usage alerts your account supports, and record a baseline of calls per pipeline run from a typical week of merge requests. Without that baseline, you cannot tell whether a control reduced spend or simply moved it.
Cost controls and when each one fits
This table compares five levers for keeping LLM API spend predictable in promptfoo CI runs, with what each one reduces, what it risks and when it fits. Read each row against your own prompt change frequency and provider rate limits. The main takeaway is that caching saves the most spend but only stays safe when the cache key changes with prompts and models.
| Control | What it reduces | What it risks | When to use it |
|---|---|---|---|
| Persist the response cache between pipelines | Repeated provider calls for unchanged test cases, so repeat runs cost far less | Stale responses can hide real regressions if the cache key does not change with prompts, models and config | Suites are large and mostly stable; confirm the cache key covers prompt text, provider, model and settings before enabling |
| Run full suites only when prompt or config files change | Spend on pipelines that touch no LLM-facing file, such as documentation or unrelated backend commits | A change in a shared file, template or dataset that is not listed in the trigger rules can skip a needed check | Your repository separates LLM assets from application code; list every dependency file in the path filter |
| Choose cheaper grader models for model-graded checks | Cost of each llm-rubric or similar judge call, which often runs once per assertion per test case | Weaker judges can miss failures or flag passing outputs, so gate results may shift without any product change | Assertions are simple or deterministic checks dominate; validate the cheaper judge against a labeled sample first |
| Cap concurrency to stay within provider rate limits | Rate-limit errors, retries and wasted calls during bursts from parallel jobs | Lower concurrency lengthens run time and can delay merge requests; retries still cost money | Several pipelines share one API key or quota; check your provider's limits and set the cap below them |
| Schedule red team scans instead of running per commit | The large number of attack probes and grader calls that a full red team run generates | Vulnerabilities introduced between scans reach the branch before they are caught | Red team suites are expensive relative to eval suites; run them on a schedule or release branches and keep per-commit evals small |
Four levers that cut spend without hiding regressions
Each lever reduces how many paid model calls a CI run makes or how fast they are made. None of them should change which tests run to a pass or fail verdict. The verification step on each card tells the team how to confirm that savings did not come from skipping checks.
Persist the response cache
promptfoo caches provider responses on disk, so an unchanged test case can reuse its earlier answer instead of calling the model again. In CI, the cache directory is lost unless the pipeline saves it between runs, so every job pays for every call. Keep the cache keyed to the prompt, model and config, and confirm the hit rate in the run log. Also run one job with the cache cleared to check that results match, because a stale cached answer can hide a regression.
promptfoo docsRun full suites only on prompt changes
Path filters limit the full eval to merge requests that touch prompts, test data, provider config or the promptfoo config itself. Application code changes that do not affect model input can run a smaller smoke set. The cost driver is the number of test cases multiplied by the number of models, so a narrow trigger cuts spend most when suites are large. Verify the filter with a change to a file outside the list and a change inside it, and confirm the full suite runs whenever a prompt file changes.
Choose the grader model deliberately
Model-graded assertions send each output to a second model, so a grader model with a higher per-token price can cost more than the system under test. A smaller grader may be adequate for simple rubrics, but it can also score differently and move pass rates. Record the grader model in the config, and compare pass rates for the same outputs under the current grader and the candidate before switching. Re-grade a fixed sample by hand to confirm the cheaper grader still agrees with reviewers.
Cap concurrency and retries
Concurrency settings control how many requests run at once, which sets the peak rate and the number of calls that can be in flight when a job fails. Retries multiply calls for every transient error, so a low concurrency limit with bounded retries keeps the bill predictable. Ask the provider for your rate limits and set concurrency below them. Verify by checking that the count of requests in a run matches the number of test cases multiplied by models, plus expected retries, and that failures are reported rather than silently retried away.
Setting up a cost-controlled promptfoo CI job
This sequence turns promptfoo CI runs from open-ended API spend into a predictable job: a pinned version, a cache that survives between pipelines, a full suite gated by changed paths, and a small smoke run that reports what each build actually called.
Pin the promptfoo version and Node.js runtime
Choose one promptfoo version and pin it in the CI job and in the lockfile rather than installing the latest release on every build. The current npm release supplied for this page, 0.124.1, requires Node.js 22.22.0 or newer, so the CI image must provide that runtime or a later compatible one. Confirm the version against the npm registry and the GitHub releases before pinning. The check: two consecutive pipeline runs print the same promptfoo version and the same Node.js version in their logs, so cache behavior and output format stay comparable between runs.
Define the paths that trigger a full suite
List the files whose changes can alter model behavior: prompt templates, the promptfoo config, test case datasets, provider definitions and any custom assertion scripts. Encode that list as CI rules so the full eval suite runs only when one of those paths changes, and a smoke run handles everything else. Ask your team to review the list when new prompt files are added, because a missing path is the most common reason a regression reaches the main branch unnoticed. The check: open a merge request that touches only a README and confirm the full-suite job is skipped, then touch one prompt file and confirm it runs.
Configure the response cache and its CI cache key
Point promptfoo's cache directory at a path the CI system can persist, then save that path between pipelines with a cache key derived from the promptfoo version and the prompt and config files. Keying on the version prevents stale responses after an upgrade, and keying on prompts means a changed prompt produces fresh calls while unchanged cases are served from cache. Store the cache on the runner or in the CI system's cache service, and confirm how long your CI platform retains caches, since that retention sets how often cold runs occur. The check: run the same job twice and confirm the second run's log reports cache hits for the test cases and no new provider calls for them.
Set the grader model and concurrency in the config
Declare the grader model used for model-graded assertions explicitly in the promptfoo configuration instead of relying on defaults, and choose a smaller model for grading where the assertion type allows it, after checking that its verdicts agree with a human-reviewed sample. Set the maximum concurrency in the config or on the command line so that parallel requests stay within the provider's rate limits and your own spend tolerance. Ask your provider which limits apply to your account and which models you are contracted to use, because those figures are set by the provider, not by promptfoo. The check: run a small set of cases with the declared grader and confirm in the output which provider and model handled each grading call.
Add a smoke run to every commit
Create a lightweight job that runs on every commit with a small, fixed set of representative test cases, a single model and no red team scan. This job catches broken configs, missing environment variables and malformed prompts before the full suite runs, and it keeps a baseline of spend that is predictable. Keep the smoke set in version control with the config so reviewers can see exactly which cases run on each commit. The check: introduce a deliberate syntax error in a prompt file and confirm the smoke job fails in under the time the full suite would take, without the full suite starting.
Record call counts and provider usage per run
Have each job write a short summary of how many test cases ran, how many were served from cache, how many provider and grader calls were made, and which model each call used. Promptfoo's JSON output can feed a script that totals these figures, and the script can post them as a job artifact or a merge request comment. Reviewers then see the cost driver of each change instead of guessing from the invoice at the end of the month. Confirm with your provider's usage dashboard that the totals in the artifact roughly match billed requests, and treat any gap as a sign that a call path is not being counted. The check: the summary for a repeat run shows a cache hit count close to the total case count and a call count near zero.
Review the cost data and tune the gates
Review the recorded call counts every few weeks with the team that owns the eval suite. Look for cases that always miss the cache, graders that call a larger model than needed, and path rules that trigger the full suite for changes that do not affect model behavior. Adjust the path list, cache key, grader choice and concurrency in one change at a time so each effect is visible in the next run's summary. Record the agreed values in the repository so that a future quote or budget discussion starts from measured usage. The check: after a change, the call count for an unchanged-prompt merge request drops, and the full-suite trigger fires only for the paths you intended.
How a commit decides between a smoke run and a full suite
The pipeline starts when a commit arrives, and a path filter checks whether prompt, config or dataset files changed. If they did, the full eval runs with the response cache restored and concurrency capped. If they did not, only a smoke subset runs. Both paths write results and save the cache, then provider usage is reviewed, so spend is checked on every run and not only when a bill arrives. Confirm that your filter covers every file that changes model inputs, because a missed path means a stale result.
Path filter routes each commit to a full eval or a smoke subset before spend is reviewed.
How the approach differs across CI systems
GitLab CI manages persistence through its cache keyword, which is set per job and keyed to values you choose. The runner decides where the cached files are stored and whether they survive into later pipelines, so the job definition and the runner setup both determine whether promptfoo reuses its cache directory or starts cold.
- Cache key: Key the cache on the promptfoo version and on the files that define prompts and tests. A prompt change then starts a fresh cache, while unchanged runs reuse stored responses.
- Runner type: Shared runners, Docker executors and Kubernetes executors can handle caching differently, so confirm whether the cache lands in GitLab storage, a local volume or an object store on your runners.
- Branch scope: Decide whether default branch and merge request pipelines share one cache. Separate caches fill more slowly and spend more on provider calls.
- Shared backend: Confirm that your runner fleet uses a shared cache backend. A cache kept on one runner rarely hits when the next job lands on a different machine.
- Full job file: The sibling topic on running promptfoo in GitLab CI covers the complete job file and masked provider variables.
Before you rely on the cache for budget planning, run the same pipeline twice and confirm with your GitLab administrator that the second run reuses the first run's cache.
Jenkins has no single built-in cache for promptfoo. Persistence depends on the agent that runs the build and on how the job manages its workspace. A pinned agent can keep a directory between builds, while a container or cloud agent usually starts empty, so the cache directory must be placed and restored deliberately.
- Workspace cleanup: Some Jenkins jobs and plugins wipe the workspace before each build. Place the promptfoo cache directory outside the workspace, in a path the agent user owns, if you want it to survive.
- Agent pool: Pinned agents keep local files between builds. Ephemeral container agents start clean unless a mounted volume or a restore step supplies the cache.
- Stash and archive: Stash and unstash steps or archived artifacts can carry the cache between builds. Transfer time and storage use grow with the size of the cache, so check both.
- Agent consistency: A cache on one agent does not help a build scheduled on another. Confirm which agents can run the promptfoo job or label them so the job stays on one pool.
- Credentials: Provider keys belong in Jenkins credentials. Credential handling does not change the cache, but it controls who can start jobs that spend.
The sibling topic on running promptfoo in Jenkins pipelines covers the Jenkinsfile itself. Confirm the cache path and restore behavior on your own agents before you assume a hit rate.
Azure Pipelines runs jobs on Microsoft-hosted agents or on self-hosted agents, and the two behave differently. Hosted agents start from a clean image on each run, so the promptfoo cache directory must be restored from the pipeline caching feature or external storage. Self-hosted agents may keep local directories between runs, subject to your own cleanup settings.
- Hosted versus self-hosted: On Microsoft-hosted agents, assume the cache directory is empty until a cache restore step runs. On self-hosted agents, check whether a workspace clean option or a scheduled cleanup removes the directory.
- Pipeline caching: Key the pipeline cache on prompt and configuration files so changes invalidate it. Confirm the size limits and expiry that apply to your organization.
- Branch scope: Confirm which branches can read a cache written on another branch, because this affects how often default branch and feature branch runs hit the cache.
- Matrix runs: Each matrix entry needs its own cache key, or entries overwrite each other's stored responses and make hit rates hard to read.
- Variable groups and Key Vault: Provider keys in variable groups or Key Vault do not change caching, but they control who can trigger runs that spend money.
The sibling topic on running promptfoo in Azure Pipelines covers the full azure-pipelines.yml. Confirm the agent type, cache behavior and expiry with your Azure DevOps administrator before setting a spend expectation.
Security risks of caching and shared provider keys
Caching and shared provider keys cut spend, but both move sensitive material into places CI systems were not built to protect. The cards below cover what the cache holds, how keys are exposed and scoped, how caches cross project boundaries, and which provider-side limits should back up the pipeline controls.
Cached responses hold sensitive data
The promptfoo cache stores model responses, and those responses often echo prompts, test fixtures and retrieved documents. Treat the cache directory as sensitive data, not as a build speed file. Store it with the same access, retention and deletion controls you apply to CI artifacts, and confirm who can download a cache from your CI system. If your test data includes customer records or regulated content, decide before enabling persistence whether that data may sit in the cache at all.
Self-hosting docsProvider keys must be masked
Provider keys reach the job as environment variables, and any step that prints configuration or fails with a verbose stack trace can expose them in the build log. Store keys in your CI secret store, mark them masked or protected where the platform supports it, and confirm the masking holds when a job fails. Check that the eval config references keys by environment variable name rather than writing them into YAML or promptfooconfig files committed to the repository.
Scope keys to the pipeline
A key that works from every branch and every project turns one leaked log or cache into a wider exposure. Create a separate key for CI eval runs, scoped to the provider project or workspace that holds only the models the suite needs. Restrict which branches or protected environments can read the key, and plan rotation so a key can be replaced without editing every pipeline. Confirm with each provider which permissions and project scopes its key model supports.
Caches must not cross projects
A cache key built only from the branch name or a shared fixed string can serve responses generated for one project to another. Include the project, the suite and the prompt or config hash in the cache key, and avoid restoring caches from untrusted forks or unprotected branches into jobs that hold provider keys. Keep red team caches separate from functional eval caches, because attack prompts and their responses should not be reused as ordinary test data.
Provider limits back up pipelines
Pipeline controls can fail, and a runaway job can spend quickly before anyone reads a report. Set budget alerts and spend caps at the provider account or project level as a second layer, sized to what a normal suite run costs in your environment. Ask each provider how alerts are delivered, whether caps stop requests or only notify, and how quickly spend data updates. Review those limits whenever the suite, concurrency or model choice changes.
Questions teams ask about controlling promptfoo CI costs
What does promptfoo cost to run in CI, and who pays for it?
promptfoo itself is free to run under the MIT license, and the Community edition includes all LLM evaluation features, all model providers and integrations, and red teaming with 10k probes per month. The recurring spend is the LLM API charges your provider bills for every model call made during an eval, grader call or red team scan. Those charges land on the account that holds the provider key your pipeline uses, so the team that owns that key owns the bill. Costs rise with suite size, the number of prompt and model combinations, the number of pipeline runs, and any model-graded assertions that call a second model. Ask your provider for usage reporting by key or project so spend can be traced to a pipeline.
How long does it take to set up cost controls for promptfoo in CI?
The setup time depends on how many pipelines run promptfoo, how large each eval suite is, and how many CI environments need the same settings. A single pipeline with a small suite is a short change, while several repositories with different runners, caches and key storage need more planning and testing. No fixed duration applies to every environment, so ask for a timeline in the written scope after the team has shared its pipeline count, suite size and CI systems. Testing the cache behavior across at least two consecutive pipeline runs is part of any honest estimate.
Can our own team control promptfoo API costs in CI without outside help?
Yes, a team with Node.js and CI experience can usually do this internally. The work involves persisting the promptfoo cache directory between runs, scoping full suite runs to changes in prompt or configuration files, selecting a lower-cost grader model for routine checks, and setting a concurrency limit that respects provider rate limits. Each change is small, but the risks are in the details, such as cache keys and branch scoping. Teams without a second engineer to review pipeline changes often benefit from an outside review of the final configuration before it runs on the default branch.
What do we need to provide for this work?
You will need to provide the following before work starts:
- Read-only or scoped provider keys for a test account, with spend limits set where the provider supports them
- Access to the CI system and repositories where promptfoo runs, with permission to edit pipeline files and cache settings
- A representative eval suite, including the configuration files, test cases and grader settings that reflect real usage
- Your current spend data by key or project, so the baseline can be compared after changes
Confirm with your provider which billing and usage reports are available, and confirm which CI runners can reach the provider endpoints.
Could caching promptfoo responses cause us to miss regressions?
Yes, a response cache can hide regressions when its keys ignore changes that affect output. If a cache key does not include the prompt text, the model name, the provider settings or the test input, a run can reuse an old response and report a pass for a change that would fail. Build the key from every input that changes the response, and clear or bypass the cache on scheduled full runs. Check the promptfoo caching documentation for the cache settings in your version, and confirm the behavior with a deliberate prompt change before relying on it in a merge gate.
Should we run the full promptfoo suite on every commit to control cost?
Usually not. Running the full suite only when prompt files, model configuration, test data or the promptfoo configuration change keeps routine commits cheap, while a scheduled full run catches drift from provider model updates. Define the trigger paths explicitly, and document which runs are gates and which are informational. A full run on the default branch or on a nightly schedule gives you a baseline that the lighter runs cannot provide.
Does using a cheaper grader model reduce the quality of our checks?
It can, because model-graded assertions depend on the grader's judgment. Use a smaller grader for simple, well-defined checks and keep a stronger grader for nuanced quality criteria, then compare both on a sample of outputs where humans already know the answer. Record which grader produced each result so pass rates stay comparable over time. Changing the grader model should be treated as a change to the test, not only a cost decision.
What a fixed-scope cost control engagement covers
A fixed-scope cost control engagement starts with a written scope agreed before any work begins. DeployOpen reviews how your pipelines currently run promptfoo: which jobs trigger on every commit, how often the promptfoo cache directory is restored or discarded, which provider keys each job uses, and how much each model and grader call costs on your accounts. The review also records which assertions use a model as the grader, because those calls add spend on top of the system under test. The output is a baseline your team can compare against after changes, so the engagement starts from measured usage rather than assumptions.
From that baseline, DeployOpen designs the trigger and cache strategy and implements it in your CI system, whether that is GitLab CI, Jenkins, Azure Pipelines or another platform you run. The design covers which changes trigger the full suite, how the cache key is built, where the cache is persisted, which grader model is used for which checks, and the concurrency limits applied to each job. Each control is documented with its setting and the reason for it, and the verification step reruns representative pipelines to confirm the behavior matches the design. Ask the vendor to show how the documented controls map to the pipeline files your team owns, so the handover does not depend on one engineer.
DeployOpen does not publish prices. A quote follows from the written scope, so the scope should name the pipelines, CI systems, provider accounts and grader models in play. Ask for the cost components broken out: the one-time design and implementation work, any changes your team must make to its own pipelines, and whether tuning after handover is included. Ongoing tuning, such as adjusting triggers as prompts change or reviewing provider usage after a model upgrade, is available as a retainer and is priced separately from the initial engagement. Confirm with DeployOpen who holds the provider keys and cache storage during and after the work.
How DeployOpen scopes and delivers promptfoo cost controls
DeployOpen approaches LLM API cost in promptfoo CI pipelines as a planning and engineering problem. We map which suites run on which changes, where the response cache lives, which grader models are used and how concurrency is capped, then build and document those controls inside your own infrastructure and CI system.
How we scope
- Inventory every promptfoo job, its trigger, provider calls and grader models in your current pipelines.
- Agree in writing which cost controls are in scope, such as cache persistence, path-based triggers and concurrency limits.
- Confirm with your provider accounts which spend limits, rate limits and billing alerts you can set and who owns them.
- Record the quote basis, including which CI systems and repositories are covered and what is excluded.
How we build
- Configure the promptfoo cache directory persistence and cache keys for your CI runner or agent type.
- Split fast prompt-change suites from full suites and wire path filters to the prompt and config files that matter.
- Set grader model choices and maximum concurrency per job, and test that a pipeline run stays within the agreed call budget.
- Store provider keys in your CI secret mechanism and verify that cache contents never include credentials.
How we hand over
- Deliver pipeline definitions, configuration files and a runbook that explains each cost control and its trade-offs.
- Document expected call counts per pipeline type so your team can compare actual spend against the design.
- Walk through the cache invalidation steps and the procedure for changing grader models or concurrency safely.
- Provide a written record of what was tested, what was changed and what your team still needs to confirm.
How we support
- Ongoing support, upgrades and continuous testing are available as retainers after the initial delivery.
- Review promptfoo version changes, such as new release lines, for effects on cache behavior and call volume.
- Re-check cost controls when you add suites, providers or CI systems, and agree the change in writing first.
- Confirm with your team who approves spend limits and who receives alerts when a pipeline exceeds its budget.

