Papers › FrugalGPT: How to Use Large Language Models While Reducing Cost and Improving Performance

FrugalGPT: How to Use Large Language Models While Reducing Cost and Improving Performance

9 May 2023arXiv:2305.05176archive 2025-07-28

Lingjiao Chen, Matei Zaharia, James Zou

There is a rapidly growing number of large language models (LLMs) that users can query for a fee. We review the cost associated with querying popular LLM APIs, e.g. GPT-4, ChatGPT, J1-Jumbo, and find that these models have heterogeneous pricing structures, with fees that can differ by two orders of magnitude. In particular, using LLMs on large collections of queries and text can be expensive. Motivated by this, we outline and discuss three types of strategies that users can exploit to reduce the inference cost associated with using LLMs: 1) prompt adaptation, 2) LLM approximation, and 3) LLM cascade. As an example, we propose FrugalGPT, a simple yet flexible instantiation of LLM cascade which learns which combinations of LLMs to use for different queries in order to reduce cost and improve accuracy. Our experiments show that FrugalGPT can match the performance of the best individual LLM (e.g. GPT-4) with up to 98% cost reduction or improve the accuracy over GPT-4 by 4% with the same cost. The ideas and findings presented here lay a foundation for using LLMs sustainably and efficiently.

PaperPDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2305.05176")

Code

Syntology Ran 0 of 11 code samples harvested from 1 repository linked to this paper; 11 have no recorded run.

By repository: community (archive-listed): 11 samples from 1 repository, 0 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

stanford-futuredata/frugalgpt mentioned on GitHubApache-2.0 report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

11 samples harvested; 0 ran; 0 honoured the contract we drafted; 11 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

11unverified

Licence: 0 of the 11 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from stanford-futuredata/frugalgpt. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

ans2opt stanford-futuredata/frugalgpt/src/FrugalGPT/scoring.py community (archive-listed) unverified Apache-2.0 (permissive) · 320a35b0624d3602 · report
compute_cost stanford-futuredata/frugalgpt/src/service/utils.py community (archive-listed) unverified Apache-2.0 (permissive) · 5141b572dad4bddf · report
compute_dist stanford-futuredata/frugalgpt/src/FrugalGPT/optimizer.py community (archive-listed) unverified Apache-2.0 (permissive) · afef112169d5fcf2 · report
compute_distance_batch stanford-futuredata/frugalgpt/src/FrugalGPT/optimizer.py community (archive-listed) unverified Apache-2.0 (permissive) · b9e4d8d1278fc2fb · report
form_keys stanford-futuredata/frugalgpt/src/FrugalGPT/llmvanilla.py community (archive-listed) unverified Apache-2.0 (permissive) · 97bed853c921dc6e · report
formatdata stanford-futuredata/frugalgpt/src/FrugalGPT/utils.py community (archive-listed) unverified Apache-2.0 (permissive) · 894f647e885ebeb9 · report
getservicename stanford-futuredata/frugalgpt/src/FrugalGPT/utils.py community (archive-listed) unverified Apache-2.0 (permissive) · 0d52632aabe1e814 · report
load_http_text stanford-futuredata/frugalgpt/src/service/utils.py community (archive-listed) unverified Apache-2.0 (permissive) · d9d512988e76223b · report
loadcsvdata stanford-futuredata/frugalgpt/src/FrugalGPT/utils.py community (archive-listed) unverified Apache-2.0 (permissive) · 23ba7d3ad1de85d6 · report
scorer_text stanford-futuredata/frugalgpt/src/FrugalGPT/llmcascade.py community (archive-listed) unverified Apache-2.0 (permissive) · 50396a05d7ac8e73 · report
table2json stanford-futuredata/frugalgpt/src/FrugalGPT/llmcascade.py community (archive-listed) unverified Apache-2.0 (permissive) · 8d5abab8c54bed5a · report

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

Absolute Position EncodingsAdamAttentionBPEDense ConnectionsDropoutGPT-4Label SmoothingLayer NormalizationLinear LayerMulti-Head AttentionPosition-Wise Feed-Forward LayerResidual ConnectionSoftmaxTransformer

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections