{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/frugalgpt-how-to-use-large-language-models","title":"FrugalGPT: How to Use Large Language Models While Reducing Cost and Improving Performance","arxiv_id":"2305.05176","date":"2023-05-09","proceeding":null,"authors":["Lingjiao Chen","Matei Zaharia","James Zou"],"abstract":"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.","url_abs":"https://arxiv.org/abs/2305.05176v1","url_pdf":"https://arxiv.org/pdf/2305.05176v1.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"frugalgpt-how-to-use-large-language-models","repo_url":"https://github.com/stanford-futuredata/frugalgpt","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"none","reach":{"status":"ok","spdx":"Apache-2.0"}}],"tasks":[],"methods":[{"method_slug":"absolute-position-encodings","method_name":"Absolute Position Encodings"},{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"bpe","method_name":"BPE"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"gpt-4","method_name":"GPT-4"},{"method_slug":"label-smoothing","method_name":"Label Smoothing"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"multi-head-attention","method_name":"Multi-Head Attention"},{"method_slug":"position-wise-feed-forward-layer","method_name":"Position-Wise Feed-Forward Layer"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"transformer","method_name":"Transformer"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2305.05176","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2305.05176"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/stanford-futuredata/frugalgpt","reach":{"status":"ok","spdx":"Apache-2.0"}}],"summary":{"unverified":11},"by_repo_kind":{"listed":{"samples":11,"ran":0,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"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"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"320a35b0624d3602","entry":"ans2opt","repo":"stanford-futuredata/frugalgpt","repo_kind":"listed","path":"src/FrugalGPT/scoring.py","file_url":"https://github.com/stanford-futuredata/frugalgpt/blob/HEAD/src/FrugalGPT/scoring.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"320a35b0624d3602"}},{"code_sha256_prefix":"5141b572dad4bddf","entry":"compute_cost","repo":"stanford-futuredata/frugalgpt","repo_kind":"listed","path":"src/service/utils.py","file_url":"https://github.com/stanford-futuredata/frugalgpt/blob/HEAD/src/service/utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"5141b572dad4bddf"}},{"code_sha256_prefix":"afef112169d5fcf2","entry":"compute_dist","repo":"stanford-futuredata/frugalgpt","repo_kind":"listed","path":"src/FrugalGPT/optimizer.py","file_url":"https://github.com/stanford-futuredata/frugalgpt/blob/HEAD/src/FrugalGPT/optimizer.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"afef112169d5fcf2"}},{"code_sha256_prefix":"b9e4d8d1278fc2fb","entry":"compute_distance_batch","repo":"stanford-futuredata/frugalgpt","repo_kind":"listed","path":"src/FrugalGPT/optimizer.py","file_url":"https://github.com/stanford-futuredata/frugalgpt/blob/HEAD/src/FrugalGPT/optimizer.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"b9e4d8d1278fc2fb"}},{"code_sha256_prefix":"97bed853c921dc6e","entry":"form_keys","repo":"stanford-futuredata/frugalgpt","repo_kind":"listed","path":"src/FrugalGPT/llmvanilla.py","file_url":"https://github.com/stanford-futuredata/frugalgpt/blob/HEAD/src/FrugalGPT/llmvanilla.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"97bed853c921dc6e"}},{"code_sha256_prefix":"894f647e885ebeb9","entry":"formatdata","repo":"stanford-futuredata/frugalgpt","repo_kind":"listed","path":"src/FrugalGPT/utils.py","file_url":"https://github.com/stanford-futuredata/frugalgpt/blob/HEAD/src/FrugalGPT/utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"894f647e885ebeb9"}},{"code_sha256_prefix":"0d52632aabe1e814","entry":"getservicename","repo":"stanford-futuredata/frugalgpt","repo_kind":"listed","path":"src/FrugalGPT/utils.py","file_url":"https://github.com/stanford-futuredata/frugalgpt/blob/HEAD/src/FrugalGPT/utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"0d52632aabe1e814"}},{"code_sha256_prefix":"d9d512988e76223b","entry":"load_http_text","repo":"stanford-futuredata/frugalgpt","repo_kind":"listed","path":"src/service/utils.py","file_url":"https://github.com/stanford-futuredata/frugalgpt/blob/HEAD/src/service/utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"d9d512988e76223b"}},{"code_sha256_prefix":"23ba7d3ad1de85d6","entry":"loadcsvdata","repo":"stanford-futuredata/frugalgpt","repo_kind":"listed","path":"src/FrugalGPT/utils.py","file_url":"https://github.com/stanford-futuredata/frugalgpt/blob/HEAD/src/FrugalGPT/utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"23ba7d3ad1de85d6"}},{"code_sha256_prefix":"50396a05d7ac8e73","entry":"scorer_text","repo":"stanford-futuredata/frugalgpt","repo_kind":"listed","path":"src/FrugalGPT/llmcascade.py","file_url":"https://github.com/stanford-futuredata/frugalgpt/blob/HEAD/src/FrugalGPT/llmcascade.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"50396a05d7ac8e73"}},{"code_sha256_prefix":"8d5abab8c54bed5a","entry":"table2json","repo":"stanford-futuredata/frugalgpt","repo_kind":"listed","path":"src/FrugalGPT/llmcascade.py","file_url":"https://github.com/stanford-futuredata/frugalgpt/blob/HEAD/src/FrugalGPT/llmcascade.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"8d5abab8c54bed5a"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}