From 2f456fdcb1fa603e71083ffdf0a24310d88885da Mon Sep 17 00:00:00 2001 From: treeoflife2 Date: Tue, 24 Nov 2026 16:41:50 +0530 Subject: [PATCH 01/12] docs(llms): send key holders to pro-api for every request Code written from llms-free.txt called the free hosts even when the user said they had an API key, so paying users hit the free rate limit. - Add a "Have an API key?" section at the top of llms.txt, llms-free.txt and llms-pro.txt: every request goes to pro-api.llama.fi, free hosts never read a key, a 429 there means the wrong host, and the $49 Pro plan has no key. - List the keyed pro-api URL under every free endpoint in llms-free.txt. - Say the same on the static homepage and in the free spec description. - Note that header and query keys get "API Key is wrong" from pro-api. - Rename the docs page key box to "API Key (API plan)". - Map free yields paths to /yields/v1/ so they keep a pro twin. --- defillama-openapi-free.json | 2 +- examples/web/index.html | 12 ++++- examples/web/src/components/ApiKeyInput.vue | 8 +++- llms-free.txt | 51 +++++++++++++++++++-- llms-pro.txt | 12 ++++- llms.txt | 12 ++++- scripts/generate-llms.ts | 49 +++++++++++++++++--- 7 files changed, 128 insertions(+), 18 deletions(-) diff --git a/defillama-openapi-free.json b/defillama-openapi-free.json index 24907dc94cd..caeb7f55046 100644 --- a/defillama-openapi-free.json +++ b/defillama-openapi-free.json @@ -1,7 +1,7 @@ { "openapi": "3.0.0", "info": { - "description": "> [!WARNING]\n> The free yield endpoints `/pools` and `/chart/{pool}` are deprecated and will shut down soon. The same data remains available on the [API plan](https://defillama.com/subscription) at `/yields/v1/pools` and `/yields/v1/chart/{pool}`.\n\n## Using AI?\n\nDefiLlama offers two ways to use our data with AI:\n\n| Resource | For | Description |\n|---|---|---|\n| llms.txt | AI assistants (ChatGPT, Claude, Cursor, etc.) | Paste this link into your AI assistant for LLM-optimized docs |\n| MCP Server | AI agents | Connect your agent directly to DefiLlama data — 23 tools, requires an API plan |\n\n**Quick start (MCP)** — paste this into your AI agent:\n```\nRead https://raw.githubusercontent.com/DefiLlama/defillama-skills/refs/heads/master/defillama-setup/SKILL.md and follow the instructions to connect to DefiLlama MCP\n```\n\n---\n\n## Authentication\n\nThe free API needs no key. If you have an API plan, use `https://pro-api.llama.fi/{YOUR_API_KEY}/...` with the key between the base URL and the endpoint. Do NOT send the key as a query parameter (`?apikey=`) or header.\n\nA 200 from `/protocols` or `/overview/fees` here does not validate your API key. Those endpoints require no authentication. A 402 here does not prove your subscription expired. It means the endpoint needs an API plan. There are only two tiers: free (no key) and the API plan. One API plan key unlocks every Pro endpoint. There are no add-ons or separate keys for volumes, derivatives, or other data.\n\nTo check that your key works, call `https://pro-api.llama.fi/usage/{YOUR_API_KEY}` (key at the end, for this endpoint only). It returns your remaining credits, like `{\"creditsLeft\": 1000000}`.\n\nNeed higher rate limits or priority support? We offer a premium plan for 300$/mo. To get it, go to https://defillama.com/subscription\n\n## SDK\n\n**JavaScript** — `npm install @defillama/api` — [GitHub](https://github.com/DefiLlama/api-sdk)\n\n**Python** — `pip install defillama-sdk` — [GitHub](https://github.com/DefiLlama/python-sdk)\n\nQuick start (JavaScript):\n```ts\nimport { DefiLlama } from '@defillama/api'\n\nconst client = new DefiLlama()\nconst protocols = await client.tvl.getProtocols()\n```\n\nQuick start (Python):\n```py\nfrom defillama_sdk import DefiLlama\n\nclient = DefiLlama()\nprotocols = client.tvl.getProtocols()\n```", + "description": "> [!WARNING]\n> The free yield endpoints `/pools` and `/chart/{pool}` are deprecated and will shut down soon. The same data remains available on the [API plan](https://defillama.com/subscription) at `/yields/v1/pools` and `/yields/v1/chart/{pool}`.\n\n## Using AI?\n\nDefiLlama offers two ways to use our data with AI:\n\n| Resource | For | Description |\n|---|---|---|\n| llms.txt | AI assistants (ChatGPT, Claude, Cursor, etc.) | Paste this link into your AI assistant for LLM-optimized docs |\n| MCP Server | AI agents | Connect your agent directly to DefiLlama data — 23 tools, requires an API plan |\n\n**Quick start (MCP)** — paste this into your AI agent:\n```\nRead https://raw.githubusercontent.com/DefiLlama/defillama-skills/refs/heads/master/defillama-setup/SKILL.md and follow the instructions to connect to DefiLlama MCP\n```\n\n---\n\n## Authentication\n\nThe free API needs no key. **Have an API key? Send every request to `https://pro-api.llama.fi/{YOUR_API_KEY}/...`, including the endpoints on this page.** The free hosts (api.llama.fi, coins.llama.fi, stablecoins.llama.fi, yields.llama.fi) never read a key, so requests there are free tier and rate limited, even for paying users. Put the key between the base URL and the endpoint, and add the pro path prefix (`/protocols` becomes `/api/protocols`, `/prices/current/{coins}` becomes `/coins/prices/current/{coins}`). Do NOT send the key as a query parameter (`?apikey=`) or header.\n\nA 200 from `/protocols` or `/overview/fees` here does not validate your API key. Those endpoints require no authentication. A 402 here does not prove your subscription expired. It means the endpoint needs an API plan. There are only two tiers: free (no key) and the API plan. One API plan key unlocks every Pro endpoint. There are no add-ons or separate keys for volumes, derivatives, or other data.\n\nTo check that your key works, call `https://pro-api.llama.fi/usage/{YOUR_API_KEY}` (key at the end, for this endpoint only). It returns your remaining credits, like `{\"creditsLeft\": 1000000}`.\n\nNeed higher rate limits or priority support? We offer a premium plan for 300$/mo. To get it, go to https://defillama.com/subscription\n\n## SDK\n\n**JavaScript** — `npm install @defillama/api` — [GitHub](https://github.com/DefiLlama/api-sdk)\n\n**Python** — `pip install defillama-sdk` — [GitHub](https://github.com/DefiLlama/python-sdk)\n\nQuick start (JavaScript):\n```ts\nimport { DefiLlama } from '@defillama/api'\n\nconst client = new DefiLlama()\nconst protocols = await client.tvl.getProtocols()\n```\n\nQuick start (Python):\n```py\nfrom defillama_sdk import DefiLlama\n\nclient = DefiLlama()\nprotocols = client.tvl.getProtocols()\n```", "version": "1.0.0-oas3", "title": "DefiLlama API", "x-scalar-sdk-installation": [ diff --git a/examples/web/index.html b/examples/web/index.html index b9441ed33af..a5712a751ee 100644 --- a/examples/web/index.html +++ b/examples/web/index.html @@ -66,8 +66,16 @@

DefiLlama API documentation

Explore free and Pro API endpoints for DeFi data.

- Free API endpoints · - Pro API endpoints + Have an API key? Send every request to + https://pro-api.llama.fi/YOUR_API_KEY/…, including + prices, TVL, stablecoins and yields. The free hosts (api.llama.fi, + coins.llama.fi, stablecoins.llama.fi, yields.llama.fi) never read a + key and are rate limited. +

+

+ Overview for AI agents · + API endpoints with a key · + Free API endpoints (no key)

diff --git a/examples/web/src/components/ApiKeyInput.vue b/examples/web/src/components/ApiKeyInput.vue index 789d2e63f70..1f818bb533d 100644 --- a/examples/web/src/components/ApiKeyInput.vue +++ b/examples/web/src/components/ApiKeyInput.vue @@ -94,7 +94,7 @@ const switchToFreeApi = () => {
-

DefiLlama Pro API Key

+

DefiLlama API Key (API plan)

diff --git a/llms-free.txt b/llms-free.txt index 44561350e32..542528b7695 100644 --- a/llms-free.txt +++ b/llms-free.txt @@ -1,6 +1,16 @@ -# DefiLlama Free API +# DefiLlama Free API (no API key) -> Free API — no authentication required. Endpoints are served from several hosts, use the base URL listed on each endpoint. +> Free API, for users with no API key. Endpoints are served from several hosts, use the base URL listed on each endpoint. Users with a key use the "With an API key" URL on each endpoint instead, or [llms-pro.txt](/llms-pro.txt). + +## Have an API key? Use pro-api.llama.fi for every request + +If you or your user has a DefiLlama API key, send every request to `https://pro-api.llama.fi/{YOUR_API_KEY}/...`. That includes TVL, token prices, stablecoins, yields, volumes and fees, which also have free hosts. + +- The free hosts (`api.llama.fi`, `coins.llama.fi`, `stablecoins.llama.fi`, `yields.llama.fi`) never read a key. Requests there are free tier and rate limited, even for paying users. A 429 from a free host means the request belongs on pro-api.llama.fi. +- The key goes in the URL path, right after the host. Headers and `?apikey=` are not read. +- Paths on pro-api.llama.fi have a prefix: `/protocols` becomes `/api/protocols`, `/prices/current/{coins}` becomes `/coins/prices/current/{coins}`, `/stablecoins` becomes `/stablecoins/stablecoins`, `/pools` becomes `/yields/pools`. +- The key comes with the DefiLlama API plan ($300/mo). If a user says they have "DefiLlama Pro" and gives you a key, it is this key: use pro-api.llama.fi. The $49 DefiLlama Pro plan on its own has no API key. +- Use the free hosts only when there is no key. **Base URL for endpoints below:** `https://api.llama.fi` (unless an endpoint lists its own) @@ -8,11 +18,13 @@ ### GET /protocols **Base URL:** `https://api.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/api/protocols` List all protocols on defillama along with their tvl Returns: array of {id, name, symbol, category, chains, tvl, chainTvls, change_1d, change_7d} ### GET /protocol/{protocol} **Base URL:** `https://api.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/api/protocol/{protocol}` Get historical TVL of a protocol and breakdowns by token and chain **Parameters:** @@ -21,11 +33,13 @@ Returns: {id, name, symbol, category, chains, currentChainTvls, chainTvls} ### GET /v2/historicalChainTvl **Base URL:** `https://api.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/api/v2/historicalChainTvl` Get historical TVL (excludes liquid staking and double counted tvl) of DeFi on all chains Returns: array of {date, tvl} ### GET /v2/historicalChainTvl/{chain} **Base URL:** `https://api.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/api/v2/historicalChainTvl/{chain}` Get historical TVL (excludes liquid staking and double counted tvl) of a chain **Parameters:** @@ -34,6 +48,7 @@ Returns: array of {date, tvl} ### GET /tvl/{protocol} **Base URL:** `https://api.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/api/tvl/{protocol}` Simplified endpoint to get current TVL of a protocol **Parameters:** @@ -42,6 +57,7 @@ Returns: number ### GET /v2/chains **Base URL:** `https://api.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/api/v2/chains` Get current TVL of all chains Returns: array of {gecko_id, tvl, tokenSymbol, cmcId, name, chainId} @@ -51,6 +67,7 @@ Returns: array of {gecko_id, tvl, tokenSymbol, cmcId, name, chainId} ### GET /prices/current/{coins} **Base URL:** `https://coins.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/coins/prices/current/{coins}` Get current prices of tokens by contract address **Parameters:** @@ -59,6 +76,7 @@ Returns: {coins} ### GET /prices/historical/{timestamp}/{coins} **Base URL:** `https://coins.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/coins/prices/historical/{timestamp}/{coins}` Get historical prices of tokens by contract address **Parameters:** @@ -68,6 +86,7 @@ Returns: {coins} ### GET /batchHistorical **Base URL:** `https://coins.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/coins/batchHistorical` Get historical prices for multiple tokens at multiple different timestamps **Parameters:** @@ -77,6 +96,7 @@ Returns: {coins} ### GET /chart/{coins} **Base URL:** `https://coins.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/coins/chart/{coins}` Get token prices at regular time intervals **Parameters:** @@ -89,6 +109,7 @@ Returns: {coins} ### GET /percentage/{coins} **Base URL:** `https://coins.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/coins/percentage/{coins}` Get percentage change in price over time **Parameters:** @@ -100,6 +121,7 @@ Returns: {coins} ### GET /prices/first/{coins} **Base URL:** `https://coins.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/coins/prices/first/{coins}` Get earliest timestamp price record for coins **Parameters:** @@ -108,6 +130,7 @@ Returns: {coins} ### GET /block/{chain}/{timestamp} **Base URL:** `https://coins.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/coins/block/{chain}/{timestamp}` Get the closest block to a timestamp **Parameters:** @@ -121,6 +144,7 @@ Returns: {height, timestamp} ### GET /stablecoins **Base URL:** `https://stablecoins.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/stablecoins/stablecoins` List all stablecoins along with their circulating amounts **Parameters:** @@ -129,6 +153,7 @@ Returns: {peggedAssets} ### GET /stablecoincharts/all **Base URL:** `https://stablecoins.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/stablecoins/stablecoincharts/all` Get historical mcap sum of all stablecoins **Parameters:** @@ -137,6 +162,7 @@ Returns: array of {date, totalCirculating} ### GET /stablecoincharts/{chain} **Base URL:** `https://stablecoins.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/stablecoins/stablecoincharts/{chain}` Get historical mcap sum of all stablecoins in a chain **Parameters:** @@ -146,6 +172,7 @@ Returns: array of {date, totalCirculating} ### GET /stablecoin/{asset} **Base URL:** `https://stablecoins.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/stablecoins/stablecoin/{asset}` Get historical mcap and historical chain distribution of a stablecoin **Parameters:** @@ -154,11 +181,13 @@ Returns: {id, name, symbol, totalCirculating, chainCirculating} ### GET /stablecoinchains **Base URL:** `https://stablecoins.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/stablecoins/stablecoinchains` Get current mcap sum of all stablecoins on each chain -Returns: array of {name, totalCirculating} +Returns: array of {name, totalCirculatingUSD} ### GET /stablecoinprices **Base URL:** `https://stablecoins.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/stablecoins/stablecoinprices` Get historical prices of all stablecoins Returns: array of {date, prices} @@ -168,11 +197,13 @@ Returns: array of {date, prices} ### GET /pools **Base URL:** `https://yields.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/yields/v1/pools` Retrieve the latest data for all pools, including enriched information such as predictions Returns: {status, data} ### GET /chart/{pool} **Base URL:** `https://yields.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/yields/v1/chart/{pool}` Get historical APY and TVL of a pool **Parameters:** @@ -185,6 +216,7 @@ Returns: {status, data} ### GET /overview/dexs **Base URL:** `https://api.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/api/overview/dexs` List all dexs along with summaries of their volumes and dataType history data **Parameters:** @@ -194,6 +226,7 @@ Returns: {protocols, totalDataChart, allChains} ### GET /overview/dexs/{chain} **Base URL:** `https://api.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/api/overview/dexs/{chain}` List all dexs along with summaries of their volumes and dataType history data filtering by chain **Parameters:** @@ -204,6 +237,7 @@ Returns: {protocols, totalDataChart} ### GET /summary/dexs/{protocol} **Base URL:** `https://api.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/api/summary/dexs/{protocol}` Get summary of dex volume with historical data **Parameters:** @@ -214,6 +248,7 @@ Returns: {name, total24h, totalAllTime, totalDataChart, totalDataChartBreakdown, ### GET /overview/options **Base URL:** `https://api.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/api/overview/options` List all options dexs along with summaries of their volumes and dataType history data **Parameters:** @@ -224,6 +259,7 @@ Returns: {protocols, totalDataChart} ### GET /overview/options/{chain} **Base URL:** `https://api.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/api/overview/options/{chain}` List all options dexs along with summaries of their volumes and dataType history data filtering by chain **Parameters:** @@ -231,14 +267,17 @@ List all options dexs along with summaries of their volumes and dataType history - `excludeTotalDataChart` (query, boolean, required) — true to exclude aggregated chart from response Example: `true` - `excludeTotalDataChartBreakdown` (query, boolean, required) — true to exclude broken down chart from response Example: `true` - `dataType` (query, string, optional) — Desired data type, dailyNotionalVolume by default. (one of: dailyPremiumVolume, dailyNotionalVolume) Example: `dailyPremiumVolume` +Returns: {totalDataChart, totalDataChartBreakdown, breakdown24h, breakdown30d, chain, allChains, total24h, total48hto24h, total7d, total14dto7d, total60dto30d, total30d, total1y, change_1d, change_7d, change_1m, change_7dover7d, change_30dover30d, total7DaysAgo, total30DaysAgo, totalAllTime, protocols} ### GET /summary/options/{protocol} **Base URL:** `https://api.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/api/summary/options/{protocol}` Get summary of options dex volume with historical data **Parameters:** - `protocol` (path, string, required) — protocol slug Example: `derive` - `dataType` (query, string, optional) — Desired data type, dailyNotionalVolume by default. (one of: dailyPremiumVolume, dailyNotionalVolume) Example: `dailyPremiumVolume` +Returns: {id, name, url, description, logo, gecko_id, cmcId, chains, twitter, governanceID, github, treasury, symbol, address, childProtocols, linkedProtocols, defillamaId, disabled, displayName, module, category, methodologyURL, methodology, forkedFrom, audits, audit_links, versionKey, parentProtocol, previousNames, slug, protocolType, total24h, total48hto24h, total7d, totalAllTime, totalDataChart, totalDataChartBreakdown, change_1d} --- @@ -246,6 +285,7 @@ Get summary of options dex volume with historical data ### GET /overview/open-interest **Base URL:** `https://api.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/api/overview/open-interest` List all open interest dex exchanges along with summaries of their open interest **Parameters:** @@ -259,6 +299,7 @@ Returns: {protocols, totalDataChart, allChains} ### GET /overview/fees **Base URL:** `https://api.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/api/overview/fees` List all protocols along with summaries of their fees and revenue and dataType history data **Parameters:** @@ -269,6 +310,7 @@ Returns: {protocols, totalDataChart, totalDataChartBreakdown} ### GET /overview/fees/{chain} **Base URL:** `https://api.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/api/overview/fees/{chain}` List all protocols along with summaries of their fees and revenue and dataType history data by chain **Parameters:** @@ -280,9 +322,10 @@ Returns: {protocols, totalDataChart, totalDataChartBreakdown} ### GET /summary/fees/{protocol} **Base URL:** `https://api.llama.fi` +**With an API key:** `https://pro-api.llama.fi/{YOUR_API_KEY}/api/summary/fees/{protocol}` Get summary of protocol fees and revenue with historical data **Parameters:** - `protocol` (path, string, required) — protocol slug Example: `derive` - `dataType` (query, string, optional) — Desired data type, dailyFees by default. (one of: dailyFees, dailyRevenue, dailyHoldersRevenue) Example: `dailyFees` -Returns: {id, name, url, referralUrl, description, logo, gecko_id, cmcId, chains, twitter, github, symbol, address, childProtocols, linkedProtocols, defillamaId, disabled, displayName, module, category, methodologyURL, methodology, forkedFrom, audits, audit_links, versionKey, governanceID, treasury, parentProtocol, previousNames, latestFetchIsOk, slug, protocolType, total24h, total48hto24h, total7d, totalAllTime, change_1d, totalDataChart, totalDataChartBreakdown} +Returns: {id, name, url, referralUrl, description, logo, gecko_id, cmcId, chains, twitter, github, symbol, address, childProtocols, linkedProtocols, defillamaId, disabled, displayName, module, category, methodologyURL, methodology, forkedFrom, audits, audit_links, versionKey, governanceID, treasury, parentProtocol, previousNames, slug, protocolType, total24h, total48hto24h, total7d, totalAllTime, change_1d, totalDataChart, totalDataChartBreakdown} diff --git a/llms-pro.txt b/llms-pro.txt index 11e2886ea56..cebcbfff56d 100644 --- a/llms-pro.txt +++ b/llms-pro.txt @@ -2,9 +2,19 @@ > Pro API — requires a paid API key ($300/mo). The pro-only endpoints below are NOT available on the free API. +## Have an API key? Use pro-api.llama.fi for every request + +If you or your user has a DefiLlama API key, send every request to `https://pro-api.llama.fi/{YOUR_API_KEY}/...`. That includes TVL, token prices, stablecoins, yields, volumes and fees, which also have free hosts. + +- The free hosts (`api.llama.fi`, `coins.llama.fi`, `stablecoins.llama.fi`, `yields.llama.fi`) never read a key. Requests there are free tier and rate limited, even for paying users. A 429 from a free host means the request belongs on pro-api.llama.fi. +- The key goes in the URL path, right after the host. Headers and `?apikey=` are not read. +- Paths on pro-api.llama.fi have a prefix: `/protocols` becomes `/api/protocols`, `/prices/current/{coins}` becomes `/coins/prices/current/{coins}`, `/stablecoins` becomes `/stablecoins/stablecoins`, `/pools` becomes `/yields/pools`. +- The key comes with the DefiLlama API plan ($300/mo). If a user says they have "DefiLlama Pro" and gives you a key, it is this key: use pro-api.llama.fi. The $49 DefiLlama Pro plan on its own has no API key. +- Use the free hosts only when there is no key. + ## Pro API authentication -Put your API key between the base URL and the endpoint. Do NOT send it as a query parameter (`?apikey=`) or header. Do NOT put it in `api.llama.fi` URLs. +Put your API key between the base URL and the endpoint. Do NOT send it as a query parameter (`?apikey=`) or header: pro-api.llama.fi does not read either and answers `500 {"error":"API Key is wrong"}`. Do NOT put it in `api.llama.fi` URLs. ``` WRONG https://pro-api.llama.fi/api/overview/derivatives?apikey={YOUR_API_KEY} diff --git a/llms.txt b/llms.txt index cd34a502fd6..157c6993a77 100644 --- a/llms.txt +++ b/llms.txt @@ -2,6 +2,16 @@ > DefiLlama provides free, open-source DeFi analytics data. There are two separate APIs with different base URLs and authentication. Do NOT mix them. +## Have an API key? Use pro-api.llama.fi for every request + +If you or your user has a DefiLlama API key, send every request to `https://pro-api.llama.fi/{YOUR_API_KEY}/...`. That includes TVL, token prices, stablecoins, yields, volumes and fees, which also have free hosts. + +- The free hosts (`api.llama.fi`, `coins.llama.fi`, `stablecoins.llama.fi`, `yields.llama.fi`) never read a key. Requests there are free tier and rate limited, even for paying users. A 429 from a free host means the request belongs on pro-api.llama.fi. +- The key goes in the URL path, right after the host. Headers and `?apikey=` are not read. +- Paths on pro-api.llama.fi have a prefix: `/protocols` becomes `/api/protocols`, `/prices/current/{coins}` becomes `/coins/prices/current/{coins}`, `/stablecoins` becomes `/stablecoins/stablecoins`, `/pools` becomes `/yields/pools`. +- The key comes with the DefiLlama API plan ($300/mo). If a user says they have "DefiLlama Pro" and gives you a key, it is this key: use pro-api.llama.fi. The $49 DefiLlama Pro plan on its own has no API key. +- Use the free hosts only when there is no key. + ## Important: Free API vs Pro API The Free API and Pro API are entirely separate services. @@ -15,7 +25,7 @@ The Free API and Pro API are entirely separate services. ## Pro API authentication -Put your API key between the base URL and the endpoint. Do NOT send it as a query parameter (`?apikey=`) or header. Do NOT put it in `api.llama.fi` URLs. +Put your API key between the base URL and the endpoint. Do NOT send it as a query parameter (`?apikey=`) or header: pro-api.llama.fi does not read either and answers `500 {"error":"API Key is wrong"}`. Do NOT put it in `api.llama.fi` URLs. ``` WRONG https://pro-api.llama.fi/api/overview/derivatives?apikey={YOUR_API_KEY} diff --git a/scripts/generate-llms.ts b/scripts/generate-llms.ts index 56f8b7aa0fb..a04980b0d89 100644 --- a/scripts/generate-llms.ts +++ b/scripts/generate-llms.ts @@ -96,10 +96,17 @@ function formatParam(p: Parameter): string { return ` - \`${p.name}\` (${p.in}, ${type}, ${req})${desc}${enumValues}${example}` } -function formatEndpoint(e: Endpoint): string { +function formatEndpoint(e: Endpoint, proPath?: string): string { const lines: string[] = [] lines.push(`### GET ${e.path}`) lines.push(`**Base URL:** \`${e.baseUrl}\``) + /** + * Agents that land on the free docs copy the free URL even when the user has a key, so paying + * users end up rate limited on the free host. Putting the keyed URL right next to it fixes that. + */ + if (proPath) { + lines.push(`**With an API key:** \`https://pro-api.llama.fi/{YOUR_API_KEY}${proPath}\``) + } lines.push(`${e.summary}`) if (e.parameters.length > 0) { @@ -152,13 +159,28 @@ function formatTagName(tag: string): string { return map[tag] ?? tag } +/** + * Goes at the top of all three files. Paying users churned because their agents read the free docs, + * kept calling the free hosts (which never read a key) and hit the free rate limit. + * "Pro" is ambiguous: the $49 DefiLlama Pro plan has no API key, the $300 API plan does. + */ +const HAVE_A_KEY = `## Have an API key? Use pro-api.llama.fi for every request + +If you or your user has a DefiLlama API key, send every request to \`https://pro-api.llama.fi/{YOUR_API_KEY}/...\`. That includes TVL, token prices, stablecoins, yields, volumes and fees, which also have free hosts. + +- The free hosts (\`api.llama.fi\`, \`coins.llama.fi\`, \`stablecoins.llama.fi\`, \`yields.llama.fi\`) never read a key. Requests there are free tier and rate limited, even for paying users. A 429 from a free host means the request belongs on pro-api.llama.fi. +- The key goes in the URL path, right after the host. Headers and \`?apikey=\` are not read. +- Paths on pro-api.llama.fi have a prefix: \`/protocols\` becomes \`/api/protocols\`, \`/prices/current/{coins}\` becomes \`/coins/prices/current/{coins}\`, \`/stablecoins\` becomes \`/stablecoins/stablecoins\`, \`/pools\` becomes \`/yields/pools\`. +- The key comes with the DefiLlama API plan ($300/mo). If a user says they have "DefiLlama Pro" and gives you a key, it is this key: use pro-api.llama.fi. The $49 DefiLlama Pro plan on its own has no API key. +- Use the free hosts only when there is no key.` + /** * Shared by llms.txt and llms-pro.txt so agents get the same auth rules from either file. * Agents kept sending the key as ?apikey= to api.llama.fi and reading the 402 as a lapsed plan. */ const PRO_AUTH = `## Pro API authentication -Put your API key between the base URL and the endpoint. Do NOT send it as a query parameter (\`?apikey=\`) or header. Do NOT put it in \`api.llama.fi\` URLs. +Put your API key between the base URL and the endpoint. Do NOT send it as a query parameter (\`?apikey=\`) or header: pro-api.llama.fi does not read either and answers \`500 {"error":"API Key is wrong"}\`. Do NOT put it in \`api.llama.fi\` URLs. \`\`\` WRONG https://pro-api.llama.fi/api/overview/derivatives?apikey={YOUR_API_KEY} @@ -183,6 +205,8 @@ function generateIndex(freeEndpoints: Endpoint[], proEndpoints: Endpoint[], mapp > DefiLlama provides free, open-source DeFi analytics data. There are two separate APIs with different base URLs and authentication. Do NOT mix them. +${HAVE_A_KEY} + ## Important: Free API vs Pro API The Free API and Pro API are entirely separate services. @@ -239,13 +263,19 @@ ${Array.from(proGroups.entries()) ` } -function generateDetailedFile(title: string, baseUrl: string, auth: string, endpoints: Endpoint[]): string { +function generateDetailedFile( + title: string, + baseUrl: string, + auth: string, + endpoints: Endpoint[], + proPaths: ReadonlyMap = new Map(), +): string { const groups = groupByTag(endpoints) const sections = Array.from(groups.entries()) .map(([tag, eps]) => { const header = `## ${formatTagName(tag)}` - const entries = eps.map(formatEndpoint).join('\n\n') + const entries = eps.map((e) => formatEndpoint(e, proPaths.get(e.path))).join('\n\n') return `${header}\n\n${entries}` }) .join('\n\n---\n\n') @@ -271,7 +301,7 @@ function buildFreeToProMapping( const proPaths = new Set(allProEndpoints.map((e) => e.path)) const mappings: { freePath: string; proPath: string; summary: string }[] = [] - const prefixes = ['/api/', '/coins/', '/stablecoins/', '/yields/'] + const prefixes = ['/api/', '/coins/', '/stablecoins/', '/yields/', '/yields/v1/'] for (const free of freeEndpoints) { for (const prefix of prefixes) { @@ -319,13 +349,18 @@ function main(): void { const llmsIndex = generateIndex(freeEndpoints, proOnlyEndpoints, mappingTable) const llmsFree = generateDetailedFile( - 'DefiLlama Free API', + 'DefiLlama Free API (no API key)', 'https://api.llama.fi', - 'Free API — no authentication required. Endpoints are served from several hosts, use the base URL listed on each endpoint.', + `Free API, for users with no API key. Endpoints are served from several hosts, use the base URL listed on each endpoint. Users with a key use the "With an API key" URL on each endpoint instead, or [llms-pro.txt](/llms-pro.txt). + +${HAVE_A_KEY}`, freeEndpoints, + new Map(freeToProMapping.map((m) => [m.freePath, m.proPath])), ) const proNote = `Pro API — requires a paid API key ($300/mo). The pro-only endpoints below are NOT available on the free API. +${HAVE_A_KEY} + ${PRO_AUTH} Pro users can also call free endpoints with higher rate limits using the path mappings below. From ffed23091cfd5a519346ca8eaff583eed17c600f Mon Sep 17 00:00:00 2001 From: treeoflife2 Date: Tue, 24 Nov 2026 16:42:03 +0530 Subject: [PATCH 02/12] test(docs): add an eval for whether integrations use pro-api run.mjs has headless coding sessions write integrations from the docs with a real key. grade.mjs runs each shipped script behind a logging proxy and records which llama.fi hosts it contacts. --- scripts/docs-eval/fixtures/dashboard.py | 30 ++++++ scripts/docs-eval/grade.mjs | 93 ++++++++++++++++++ scripts/docs-eval/run.mjs | 121 ++++++++++++++++++++++++ 3 files changed, 244 insertions(+) create mode 100644 scripts/docs-eval/fixtures/dashboard.py create mode 100644 scripts/docs-eval/grade.mjs create mode 100644 scripts/docs-eval/run.mjs diff --git a/scripts/docs-eval/fixtures/dashboard.py b/scripts/docs-eval/fixtures/dashboard.py new file mode 100644 index 00000000000..83ba7361aa9 --- /dev/null +++ b/scripts/docs-eval/fixtures/dashboard.py @@ -0,0 +1,30 @@ +import os +import time +import requests + +API_KEY = os.environ.get("DEFILLAMA_API_KEY") + + +def get_top_protocols(n=5): + protocols = requests.get("https://api.llama.fi/protocols").json() + protocols.sort(key=lambda p: p.get("tvl") or 0, reverse=True) + return [(p["name"], p["tvl"]) for p in protocols[:n]] + + +def get_prices(): + r = requests.get("https://coins.llama.fi/prices/current/coingecko:ethereum,coingecko:bitcoin") + r.raise_for_status() + return {k: v["price"] for k, v in r.json()["coins"].items()} + + +def get_stablecoin_total(): + data = requests.get("https://stablecoins.llama.fi/stablecoins").json() + return sum(s["circulating"].get("peggedUSD", 0) for s in data["peggedAssets"]) + + +if __name__ == "__main__": + for i in range(3): + print(get_top_protocols()) + print(get_prices()) + print(get_stablecoin_total()) + time.sleep(1) diff --git a/scripts/docs-eval/grade.mjs b/scripts/docs-eval/grade.mjs new file mode 100644 index 00000000000..9dc443e28fa --- /dev/null +++ b/scripts/docs-eval/grade.mjs @@ -0,0 +1,93 @@ +/** + * Grades an agent-eval run by behavior, not by grepping: every script the agent shipped runs with the + * key set, behind a local proxy that records which hosts it connects to. A script that uses pro-api + * when a key is set and falls back to a free host without one passes, a grep would flag it. + * + * Usage: DEFILLAMA_API_KEY=... node scripts/docs-eval/grade.mjs
diff --git a/llms-free.txt b/llms-free.txt index 542528b7695..adc452a0002 100644 --- a/llms-free.txt +++ b/llms-free.txt @@ -9,7 +9,7 @@ If you or your user has a DefiLlama API key, send every request to `https://pro- - The free hosts (`api.llama.fi`, `coins.llama.fi`, `stablecoins.llama.fi`, `yields.llama.fi`) never read a key. Requests there are free tier and rate limited, even for paying users. A 429 from a free host means the request belongs on pro-api.llama.fi. - The key goes in the URL path, right after the host. Headers and `?apikey=` are not read. - Paths on pro-api.llama.fi have a prefix: `/protocols` becomes `/api/protocols`, `/prices/current/{coins}` becomes `/coins/prices/current/{coins}`, `/stablecoins` becomes `/stablecoins/stablecoins`, `/pools` becomes `/yields/pools`. -- The key comes with the DefiLlama API plan ($300/mo). If a user says they have "DefiLlama Pro" and gives you a key, it is this key: use pro-api.llama.fi. The $49 DefiLlama Pro plan on its own has no API key. +- Whatever the user calls their plan ("API plan", "Pro", "pro API"), if they have a DefiLlama API key, use pro-api.llama.fi. - Use the free hosts only when there is no key. **Base URL for endpoints below:** `https://api.llama.fi` (unless an endpoint lists its own) diff --git a/llms-pro.txt b/llms-pro.txt index cebcbfff56d..b87c7a1cad8 100644 --- a/llms-pro.txt +++ b/llms-pro.txt @@ -9,7 +9,7 @@ If you or your user has a DefiLlama API key, send every request to `https://pro- - The free hosts (`api.llama.fi`, `coins.llama.fi`, `stablecoins.llama.fi`, `yields.llama.fi`) never read a key. Requests there are free tier and rate limited, even for paying users. A 429 from a free host means the request belongs on pro-api.llama.fi. - The key goes in the URL path, right after the host. Headers and `?apikey=` are not read. - Paths on pro-api.llama.fi have a prefix: `/protocols` becomes `/api/protocols`, `/prices/current/{coins}` becomes `/coins/prices/current/{coins}`, `/stablecoins` becomes `/stablecoins/stablecoins`, `/pools` becomes `/yields/pools`. -- The key comes with the DefiLlama API plan ($300/mo). If a user says they have "DefiLlama Pro" and gives you a key, it is this key: use pro-api.llama.fi. The $49 DefiLlama Pro plan on its own has no API key. +- Whatever the user calls their plan ("API plan", "Pro", "pro API"), if they have a DefiLlama API key, use pro-api.llama.fi. - Use the free hosts only when there is no key. ## Pro API authentication diff --git a/llms.txt b/llms.txt index 157c6993a77..934ba96f07a 100644 --- a/llms.txt +++ b/llms.txt @@ -9,7 +9,7 @@ If you or your user has a DefiLlama API key, send every request to `https://pro- - The free hosts (`api.llama.fi`, `coins.llama.fi`, `stablecoins.llama.fi`, `yields.llama.fi`) never read a key. Requests there are free tier and rate limited, even for paying users. A 429 from a free host means the request belongs on pro-api.llama.fi. - The key goes in the URL path, right after the host. Headers and `?apikey=` are not read. - Paths on pro-api.llama.fi have a prefix: `/protocols` becomes `/api/protocols`, `/prices/current/{coins}` becomes `/coins/prices/current/{coins}`, `/stablecoins` becomes `/stablecoins/stablecoins`, `/pools` becomes `/yields/pools`. -- The key comes with the DefiLlama API plan ($300/mo). If a user says they have "DefiLlama Pro" and gives you a key, it is this key: use pro-api.llama.fi. The $49 DefiLlama Pro plan on its own has no API key. +- Whatever the user calls their plan ("API plan", "Pro", "pro API"), if they have a DefiLlama API key, use pro-api.llama.fi. - Use the free hosts only when there is no key. ## Important: Free API vs Pro API diff --git a/scripts/docs-eval/fixtures/dashboard.py b/scripts/docs-eval/fixtures/dashboard.py deleted file mode 100644 index 83ba7361aa9..00000000000 --- a/scripts/docs-eval/fixtures/dashboard.py +++ /dev/null @@ -1,30 +0,0 @@ -import os -import time -import requests - -API_KEY = os.environ.get("DEFILLAMA_API_KEY") - - -def get_top_protocols(n=5): - protocols = requests.get("https://api.llama.fi/protocols").json() - protocols.sort(key=lambda p: p.get("tvl") or 0, reverse=True) - return [(p["name"], p["tvl"]) for p in protocols[:n]] - - -def get_prices(): - r = requests.get("https://coins.llama.fi/prices/current/coingecko:ethereum,coingecko:bitcoin") - r.raise_for_status() - return {k: v["price"] for k, v in r.json()["coins"].items()} - - -def get_stablecoin_total(): - data = requests.get("https://stablecoins.llama.fi/stablecoins").json() - return sum(s["circulating"].get("peggedUSD", 0) for s in data["peggedAssets"]) - - -if __name__ == "__main__": - for i in range(3): - print(get_top_protocols()) - print(get_prices()) - print(get_stablecoin_total()) - time.sleep(1) diff --git a/scripts/docs-eval/grade.mjs b/scripts/docs-eval/grade.mjs deleted file mode 100644 index 9dc443e28fa..00000000000 --- a/scripts/docs-eval/grade.mjs +++ /dev/null @@ -1,93 +0,0 @@ -/** - * Grades an agent-eval run by behavior, not by grepping: every script the agent shipped runs with the - * key set, behind a local proxy that records which hosts it connects to. A script that uses pro-api - * when a key is set and falls back to a free host without one passes, a grep would flag it. - * - * Usage: DEFILLAMA_API_KEY=... node scripts/docs-eval/grade.mjs