diff --git a/defillama-openapi-free.json b/defillama-openapi-free.json index 24907dc94cd..078528bcd2c 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": [ @@ -58,6 +58,7 @@ "get": { "tags": ["TVL"], "summary": "List all protocols on defillama along with their tvl", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/api/protocols` instead. This host does not read keys and is rate limited.", "responses": { "200": { "description": "Array of all protocols with their TVL data", @@ -141,6 +142,7 @@ "get": { "tags": ["TVL"], "summary": "Get historical TVL of a protocol and breakdowns by token and chain", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/api/protocol/{protocol}` instead. This host does not read keys and is rate limited.", "parameters": [ { "name": "protocol", @@ -268,6 +270,7 @@ "get": { "tags": ["TVL"], "summary": "Get historical TVL (excludes liquid staking and double counted tvl) of DeFi on all chains", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/api/v2/historicalChainTvl` instead. This host does not read keys and is rate limited.", "responses": { "200": { "description": "Historical TVL data for all chains combined", @@ -313,6 +316,7 @@ "get": { "tags": ["TVL"], "summary": "Get historical TVL (excludes liquid staking and double counted tvl) of a chain", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/api/v2/historicalChainTvl/{chain}` instead. This host does not read keys and is rate limited.", "parameters": [ { "name": "chain", @@ -373,7 +377,7 @@ "get": { "tags": ["TVL"], "summary": "Simplified endpoint to get current TVL of a protocol", - "description": "Simplified endpoint that only returns a number, the current TVL of a protocol", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/api/tvl/{protocol}` instead. This host does not read keys and is rate limited.\n\nSimplified endpoint that only returns a number, the current TVL of a protocol", "parameters": [ { "name": "protocol", @@ -421,6 +425,7 @@ "get": { "tags": ["TVL"], "summary": "Get current TVL of all chains", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/api/v2/chains` instead. This host does not read keys and is rate limited.", "responses": { "200": { "description": "Array of all chains with their TVL data", @@ -490,7 +495,7 @@ "get": { "tags": ["coins"], "summary": "Get current prices of tokens by contract address", - "description": "The goal of this API is to price as many tokens as possible, including exotic ones that never get traded, which makes them impossible to price by looking at markets.\n\nThe base of our data are prices pulled from coingecko, which is then extended through multiple means:\n- We price all bridged tokens by using the price of the token in it's original chain, so we fetch all bridged versions of USDC on arbitrum, fantom, avax... and price all them using the price for the token on Ethereum, which we know. Right now we support 10 different bridging protocols.\n- We have multiple adapters to price specialized sets of tokens by running custom code:\n - We price yearn's yToken LPs by checking how much underlying token can be withdrawn for each LP\n - Aave, compound and euler LP tokens are also priced based on their relationship against underlying tokens\n - Uniswap, curve, balancer and stargate LPs are priced using the underlying tokens in each pair\n - GMX's GLP token is priced based on the value of tokens given on withdrawal (which includes calculations based on trader's PnL)\n \n - Synthetix tokens are priced using forex prices of the coin they are pegged to\n- For tokens that we haven't been able to price in any other way, we find the pool with most liquidity for each on uniswap, curve and serum and then use the prices provided on those exchanges.\n \n Unlike all the other tokens, we can't confirm that these prices are correct, so we only ingest the ones that have sufficient liquidity and, even in that case, we attach a `confidence` value to them that is related to the depth of liquidity and which represents our confidence in the quality of each price. API consumers can choose to filter out prices with low confidence values.\n \n Our API server is fully open source and we are constantly adding more pricing adapters, extending the amount of tokens we support.\n \nTokens are queried using {chain}:{address}, where chain is an identifier such as ethereum, bsc, polygon, avax... You can also get tokens by coingecko id by setting `coingecko` as the chain, eg: coingecko:ethereum, coingecko:bitcoin. Examples:\n - ethereum:0xdF574c24545E5FfEcb9a659c229253D4111d87e1\n - bsc:0x762539b45a1dcce3d36d080f74d1aed37844b878\n - coingecko:ethereum\n - arbitrum:0x4277f8f2c384827b5273592ff7cebd9f2c1ac258\n", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/coins/prices/current/{coins}` instead. This host does not read keys and is rate limited.\n\nThe goal of this API is to price as many tokens as possible, including exotic ones that never get traded, which makes them impossible to price by looking at markets.\n\nThe base of our data are prices pulled from coingecko, which is then extended through multiple means:\n- We price all bridged tokens by using the price of the token in it's original chain, so we fetch all bridged versions of USDC on arbitrum, fantom, avax... and price all them using the price for the token on Ethereum, which we know. Right now we support 10 different bridging protocols.\n- We have multiple adapters to price specialized sets of tokens by running custom code:\n - We price yearn's yToken LPs by checking how much underlying token can be withdrawn for each LP\n - Aave, compound and euler LP tokens are also priced based on their relationship against underlying tokens\n - Uniswap, curve, balancer and stargate LPs are priced using the underlying tokens in each pair\n - GMX's GLP token is priced based on the value of tokens given on withdrawal (which includes calculations based on trader's PnL)\n \n - Synthetix tokens are priced using forex prices of the coin they are pegged to\n- For tokens that we haven't been able to price in any other way, we find the pool with most liquidity for each on uniswap, curve and serum and then use the prices provided on those exchanges.\n \n Unlike all the other tokens, we can't confirm that these prices are correct, so we only ingest the ones that have sufficient liquidity and, even in that case, we attach a `confidence` value to them that is related to the depth of liquidity and which represents our confidence in the quality of each price. API consumers can choose to filter out prices with low confidence values.\n \n Our API server is fully open source and we are constantly adding more pricing adapters, extending the amount of tokens we support.\n \nTokens are queried using {chain}:{address}, where chain is an identifier such as ethereum, bsc, polygon, avax... You can also get tokens by coingecko id by setting `coingecko` as the chain, eg: coingecko:ethereum, coingecko:bitcoin. Examples:\n - ethereum:0xdF574c24545E5FfEcb9a659c229253D4111d87e1\n - bsc:0x762539b45a1dcce3d36d080f74d1aed37844b878\n - coingecko:ethereum\n - arbitrum:0x4277f8f2c384827b5273592ff7cebd9f2c1ac258\n", "servers": [ { "url": "https://coins.llama.fi" @@ -576,7 +581,7 @@ "get": { "tags": ["coins"], "summary": "Get historical prices of tokens by contract address", - "description": "See /prices/current for explanation on how prices are sourced.", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/coins/prices/historical/{timestamp}/{coins}` instead. This host does not read keys and is rate limited.\n\nSee /prices/current for explanation on how prices are sourced.", "servers": [ { "url": "https://coins.llama.fi" @@ -672,6 +677,7 @@ "get": { "tags": ["coins"], "summary": "Get historical prices for multiple tokens at multiple different timestamps", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/coins/batchHistorical` instead. This host does not read keys and is rate limited.", "servers": [ { "url": "https://coins.llama.fi" @@ -758,7 +764,7 @@ "get": { "tags": ["coins"], "summary": "Get token prices at regular time intervals", - "description": "Strings accepted by period:\nCan use regular chart candle notion like ‘4h’ etc where:\nW = week, D = day, H = hour, M = minute (not case sensitive)\n", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/coins/chart/{coins}` instead. This host does not read keys and is rate limited.\n\nStrings accepted by period:\nCan use regular chart candle notion like ‘4h’ etc where:\nW = week, D = day, H = hour, M = minute (not case sensitive)\n", "servers": [ { "url": "https://coins.llama.fi" @@ -892,7 +898,7 @@ "get": { "tags": ["coins"], "summary": "Get percentage change in price over time", - "description": "Strings accepted by period:\nCan use regular chart candle notion like ‘4h’ etc where:\nW = week, D = day, H = hour, M = minute (not case sensitive)\n", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/coins/percentage/{coins}` instead. This host does not read keys and is rate limited.\n\nStrings accepted by period:\nCan use regular chart candle notion like ‘4h’ etc where:\nW = week, D = day, H = hour, M = minute (not case sensitive)\n", "servers": [ { "url": "https://coins.llama.fi" @@ -984,6 +990,7 @@ "get": { "tags": ["coins"], "summary": "Get earliest timestamp price record for coins", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/coins/prices/first/{coins}` instead. This host does not read keys and is rate limited.", "servers": [ { "url": "https://coins.llama.fi" @@ -1058,7 +1065,7 @@ "get": { "tags": ["coins"], "summary": "Get the closest block to a timestamp", - "description": "Runs binary search over a blockchain's blocks to get the closest one to a timestamp.\nEvery time this is run we add new data to our database, so each query permanently speeds up future queries.\n", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/coins/block/{chain}/{timestamp}` instead. This host does not read keys and is rate limited.\n\nRuns binary search over a blockchain's blocks to get the closest one to a timestamp.\nEvery time this is run we add new data to our database, so each query permanently speeds up future queries.\n", "servers": [ { "url": "https://coins.llama.fi" @@ -1131,6 +1138,7 @@ "get": { "tags": ["stablecoins"], "summary": "List all stablecoins along with their circulating amounts", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/stablecoins/stablecoins` instead. This host does not read keys and is rate limited.", "servers": [ { "url": "https://stablecoins.llama.fi" @@ -1246,6 +1254,7 @@ "get": { "tags": ["stablecoins"], "summary": "Get historical mcap sum of all stablecoins", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/stablecoins/stablecoincharts/all` instead. This host does not read keys and is rate limited.", "servers": [ { "url": "https://stablecoins.llama.fi" @@ -1312,6 +1321,7 @@ "get": { "tags": ["stablecoins"], "summary": "Get historical mcap sum of all stablecoins in a chain", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/stablecoins/stablecoincharts/{chain}` instead. This host does not read keys and is rate limited.", "servers": [ { "url": "https://stablecoins.llama.fi" @@ -1388,6 +1398,7 @@ "get": { "tags": ["stablecoins"], "summary": "Get historical mcap and historical chain distribution of a stablecoin", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/stablecoins/stablecoin/{asset}` instead. This host does not read keys and is rate limited.", "servers": [ { "url": "https://stablecoins.llama.fi" @@ -1484,6 +1495,7 @@ "get": { "tags": ["stablecoins"], "summary": "Get current mcap sum of all stablecoins on each chain", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/stablecoins/stablecoinchains` instead. This host does not read keys and is rate limited.", "servers": [ { "url": "https://stablecoins.llama.fi" @@ -1538,6 +1550,7 @@ "get": { "tags": ["stablecoins"], "summary": "Get historical prices of all stablecoins", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/stablecoins/stablecoinprices` instead. This host does not read keys and is rate limited.", "servers": [ { "url": "https://stablecoins.llama.fi" @@ -1594,7 +1607,7 @@ "tags": ["yields"], "summary": "Retrieve the latest data for all pools, including enriched information such as predictions", "deprecated": true, - "description": "**This endpoint is deprecated and will shut down soon.** The same data remains available at `/yields/v1/pools` on the [API plan](https://defillama.com/subscription).", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/yields/v1/pools` instead. This host does not read keys and is rate limited.\n\n**This endpoint is deprecated and will shut down soon.** The same data remains available at `/yields/v1/pools` on the [API plan](https://defillama.com/subscription).", "servers": [ { "url": "https://yields.llama.fi" @@ -1776,7 +1789,7 @@ "tags": ["yields"], "summary": "Get historical APY and TVL of a pool", "deprecated": true, - "description": "**This endpoint is deprecated and will shut down soon.** The same data remains available at `/yields/v1/chart/{pool}` on the [API plan](https://defillama.com/subscription).", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/yields/v1/chart/{pool}` instead. This host does not read keys and is rate limited.\n\n**This endpoint is deprecated and will shut down soon.** The same data remains available at `/yields/v1/chart/{pool}` on the [API plan](https://defillama.com/subscription).", "servers": [ { "url": "https://yields.llama.fi" @@ -1858,6 +1871,7 @@ "get": { "tags": ["volumes"], "summary": "List all dexs along with summaries of their volumes and dataType history data", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/api/overview/dexs` instead. This host does not read keys and is rate limited.", "servers": [ { "url": "https://api.llama.fi" @@ -1981,6 +1995,7 @@ "get": { "tags": ["volumes"], "summary": "List all dexs along with summaries of their volumes and dataType history data filtering by chain", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/api/overview/dexs/{chain}` instead. This host does not read keys and is rate limited.", "servers": [ { "url": "https://api.llama.fi" @@ -2078,6 +2093,7 @@ "get": { "tags": ["volumes"], "summary": "Get summary of dex volume with historical data", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/api/summary/dexs/{protocol}` instead. This host does not read keys and is rate limited.", "servers": [ { "url": "https://api.llama.fi" @@ -2186,6 +2202,7 @@ "get": { "tags": ["volumes"], "summary": "List all options dexs along with summaries of their volumes and dataType history data", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/api/overview/options` instead. This host does not read keys and is rate limited.", "servers": [ { "url": "https://api.llama.fi" @@ -2284,6 +2301,7 @@ "get": { "tags": ["volumes"], "summary": "List all options dexs along with summaries of their volumes and dataType history data filtering by chain", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/api/overview/options/{chain}` instead. This host does not read keys and is rate limited.", "servers": [ { "url": "https://api.llama.fi" @@ -2623,6 +2641,7 @@ "get": { "tags": ["volumes"], "summary": "Get summary of options dex volume with historical data", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/api/summary/options/{protocol}` instead. This host does not read keys and is rate limited.", "servers": [ { "url": "https://api.llama.fi" @@ -2903,6 +2922,7 @@ "get": { "tags": ["perps"], "summary": "List all open interest dex exchanges along with summaries of their open interest", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/api/overview/open-interest` instead. This host does not read keys and is rate limited.", "servers": [ { "url": "https://api.llama.fi" @@ -3014,6 +3034,7 @@ "get": { "tags": ["fees and revenue"], "summary": "List all protocols along with summaries of their fees and revenue and dataType history data", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/api/overview/fees` instead. This host does not read keys and is rate limited.", "servers": [ { "url": "https://api.llama.fi" @@ -3132,6 +3153,7 @@ "get": { "tags": ["fees and revenue"], "summary": "List all protocols along with summaries of their fees and revenue and dataType history data by chain", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/api/overview/fees/{chain}` instead. This host does not read keys and is rate limited.", "servers": [ { "url": "https://api.llama.fi" @@ -3260,6 +3282,7 @@ "get": { "tags": ["fees and revenue"], "summary": "Get summary of protocol fees and revenue with historical data", + "description": "**With an API key:** use `https://pro-api.llama.fi/{YOUR_API_KEY}/api/summary/fees/{protocol}` instead. This host does not read keys and is rate limited.", "servers": [ { "url": "https://api.llama.fi" 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..a0118e9f071 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..827e2e6f19d 100644 --- a/llms-free.txt +++ b/llms-free.txt @@ -1,6 +1,22 @@ -# 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. Each endpoint lists its free base URL and, under it, the URL to use with a key. + +## Have an API key? Use pro-api.llama.fi for every request + +If you or your user has a DefiLlama API key, whatever the plan is called ("API plan", "Pro", "pro API"), send every request to `https://pro-api.llama.fi/{YOUR_API_KEY}/...`. That includes TVL, prices, stablecoins, yields, volumes and fees, and any fallback or secondary lookup. Use the free hosts only when there is no key. + +``` +RIGHT https://pro-api.llama.fi/{YOUR_API_KEY}/coins/prices/current/coingecko:ethereum +WRONG https://coins.llama.fi/prices/current/coingecko:ethereum (free host: ignores the key, rate limited) +WRONG https://pro-api.llama.fi/coins/prices/current/coingecko:ethereum?apikey={YOUR_API_KEY} (key not in the path) +``` + +- The free hosts (`api.llama.fi`, `coins.llama.fi`, `stablecoins.llama.fi`, `yields.llama.fi`) never read a key, so a 429 there means the request belongs on pro-api.llama.fi. A 402 there means the endpoint needs pro-api, not that the plan expired. +- The key goes in the path, right after the host. Headers and `?apikey=` are not read: pro-api answers `500 {"error":"API Key is wrong"}`. +- Paths on pro-api have a prefix: `/protocols` becomes `/api/protocols`, `/prices/current/{coins}` becomes `/coins/prices/current/{coins}`, `/stablecoins` becomes `/stablecoins/stablecoins`, `/pools` becomes `/yields/v1/pools`. Every free path is mapped in [llms.txt](https://api-docs.defillama.com/llms.txt), and the pro-only endpoints are in [llms-pro.txt](https://api-docs.defillama.com/llms-pro.txt). +- One key unlocks every endpoint. There are no add-ons or separate keys. +- To check a key, call `https://pro-api.llama.fi/usage/{YOUR_API_KEY}` (key at the end, for this endpoint only). It returns `{"creditsLeft": ...}`. A 200 from a free host proves nothing, those endpoints need no key. **Base URL for endpoints below:** `https://api.llama.fi` (unless an endpoint lists its own) @@ -8,11 +24,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 +39,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 +54,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 +63,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 +73,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 +82,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 +92,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 +102,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 +115,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 +127,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 +136,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 +150,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 +159,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 +168,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 +178,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 +187,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 +203,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 +222,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 +232,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 +243,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 +254,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 +265,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 +273,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 +291,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 +305,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 +316,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 +328,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..857962274fa 100644 --- a/llms-pro.txt +++ b/llms-pro.txt @@ -2,30 +2,25 @@ > Pro API — requires a paid API key ($300/mo). The pro-only endpoints below are NOT available on the free API. -## Pro API authentication +## Have an API key? Use pro-api.llama.fi for every request -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. +If you or your user has a DefiLlama API key, whatever the plan is called ("API plan", "Pro", "pro API"), send every request to `https://pro-api.llama.fi/{YOUR_API_KEY}/...`. That includes TVL, prices, stablecoins, yields, volumes and fees, and any fallback or secondary lookup. Use the free hosts only when there is no key. ``` -WRONG https://pro-api.llama.fi/api/overview/derivatives?apikey={YOUR_API_KEY} -RIGHT https://pro-api.llama.fi/{YOUR_API_KEY}/api/overview/derivatives +RIGHT https://pro-api.llama.fi/{YOUR_API_KEY}/coins/prices/current/coingecko:ethereum +WRONG https://coins.llama.fi/prices/current/coingecko:ethereum (free host: ignores the key, rate limited) +WRONG https://pro-api.llama.fi/coins/prices/current/coingecko:ethereum?apikey={YOUR_API_KEY} (key not in the path) ``` -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. - -## Troubleshooting - -A 200 from `/protocols` or `/overview/fees` on `api.llama.fi` does not validate your API key. Those endpoints require no authentication. A 402 from `api.llama.fi` does not prove your subscription expired. It means the endpoint needs the Pro API. - -1. Check the host and key placement: `https://pro-api.llama.fi/{YOUR_API_KEY}/...`, not `api.llama.fi` and not `?apikey=`. -2. 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}`. -3. Retry the keyed URL: `https://pro-api.llama.fi/{YOUR_API_KEY}/api/overview/derivatives`. - -Pro users can also call free endpoints with higher rate limits using the path mappings below. +- The free hosts (`api.llama.fi`, `coins.llama.fi`, `stablecoins.llama.fi`, `yields.llama.fi`) never read a key, so a 429 there means the request belongs on pro-api.llama.fi. A 402 there means the endpoint needs pro-api, not that the plan expired. +- The key goes in the path, right after the host. Headers and `?apikey=` are not read: pro-api answers `500 {"error":"API Key is wrong"}`. +- Paths on pro-api have a prefix: `/protocols` becomes `/api/protocols`, `/prices/current/{coins}` becomes `/coins/prices/current/{coins}`, `/stablecoins` becomes `/stablecoins/stablecoins`, `/pools` becomes `/yields/v1/pools`. Every free path is mapped in [llms.txt](https://api-docs.defillama.com/llms.txt), and the pro-only endpoints are in [llms-pro.txt](https://api-docs.defillama.com/llms-pro.txt). +- One key unlocks every endpoint. There are no add-ons or separate keys. +- To check a key, call `https://pro-api.llama.fi/usage/{YOUR_API_KEY}` (key at the end, for this endpoint only). It returns `{"creditsLeft": ...}`. A 200 from a free host proves nothing, those endpoints need no key. ## Free Endpoints Available on Pro (Higher Rate Limits) -Use base URL https://pro-api.llama.fi/{YOUR_API_KEY} with the pro path column. +Call these on `https://pro-api.llama.fi/{YOUR_API_KEY}` with the pro path. | Free path | Pro path (pro-api.llama.fi) | Description | |---|---|---| @@ -48,8 +43,8 @@ Use base URL https://pro-api.llama.fi/{YOUR_API_KEY} with the pro path column. | `/stablecoin/{asset}` | `/stablecoins/stablecoin/{asset}` | Get historical mcap and historical chain distribution of a stablecoin | | `/stablecoinchains` | `/stablecoins/stablecoinchains` | Get current mcap sum of all stablecoins on each chain | | `/stablecoinprices` | `/stablecoins/stablecoinprices` | Get historical prices of all stablecoins | -| `/pools` | `/yields/pools` | Retrieve the latest data for all pools, including enriched information such as predictions | -| `/chart/{pool}` | `/yields/chart/{pool}` | Get historical APY and TVL of a pool | +| `/pools` | `/yields/v1/pools` | Retrieve the latest data for all pools, including enriched information such as predictions | +| `/chart/{pool}` | `/yields/v1/chart/{pool}` | Get historical APY and TVL of a pool | | `/overview/dexs` | `/api/overview/dexs` | List all dexs along with summaries of their volumes and dataType history data | | `/overview/dexs/{chain}` | `/api/overview/dexs/{chain}` | List all dexs along with summaries of their volumes and dataType history data filtering by chain | | `/summary/dexs/{protocol}` | `/api/summary/dexs/{protocol}` | Get summary of dex volume with historical data | diff --git a/llms.txt b/llms.txt index cd34a502fd6..b712f29a883 100644 --- a/llms.txt +++ b/llms.txt @@ -2,6 +2,22 @@ > 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, whatever the plan is called ("API plan", "Pro", "pro API"), send every request to `https://pro-api.llama.fi/{YOUR_API_KEY}/...`. That includes TVL, prices, stablecoins, yields, volumes and fees, and any fallback or secondary lookup. Use the free hosts only when there is no key. + +``` +RIGHT https://pro-api.llama.fi/{YOUR_API_KEY}/coins/prices/current/coingecko:ethereum +WRONG https://coins.llama.fi/prices/current/coingecko:ethereum (free host: ignores the key, rate limited) +WRONG https://pro-api.llama.fi/coins/prices/current/coingecko:ethereum?apikey={YOUR_API_KEY} (key not in the path) +``` + +- The free hosts (`api.llama.fi`, `coins.llama.fi`, `stablecoins.llama.fi`, `yields.llama.fi`) never read a key, so a 429 there means the request belongs on pro-api.llama.fi. A 402 there means the endpoint needs pro-api, not that the plan expired. +- The key goes in the path, right after the host. Headers and `?apikey=` are not read: pro-api answers `500 {"error":"API Key is wrong"}`. +- Paths on pro-api have a prefix: `/protocols` becomes `/api/protocols`, `/prices/current/{coins}` becomes `/coins/prices/current/{coins}`, `/stablecoins` becomes `/stablecoins/stablecoins`, `/pools` becomes `/yields/v1/pools`. Every free path is mapped in [llms.txt](https://api-docs.defillama.com/llms.txt), and the pro-only endpoints are in [llms-pro.txt](https://api-docs.defillama.com/llms-pro.txt). +- One key unlocks every endpoint. There are no add-ons or separate keys. +- To check a key, call `https://pro-api.llama.fi/usage/{YOUR_API_KEY}` (key at the end, for this endpoint only). It returns `{"creditsLeft": ...}`. A 200 from a free host proves nothing, those endpoints need no key. + ## Important: Free API vs Pro API The Free API and Pro API are entirely separate services. @@ -13,30 +29,9 @@ The Free API and Pro API are entirely separate services. | Rate Limit | Standard | Higher | | Endpoints | 31 | 38 exclusive + 31 free with prefix | -## 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. - -``` -WRONG https://pro-api.llama.fi/api/overview/derivatives?apikey={YOUR_API_KEY} -RIGHT https://pro-api.llama.fi/{YOUR_API_KEY}/api/overview/derivatives -``` - -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. - -## Troubleshooting - -A 200 from `/protocols` or `/overview/fees` on `api.llama.fi` does not validate your API key. Those endpoints require no authentication. A 402 from `api.llama.fi` does not prove your subscription expired. It means the endpoint needs the Pro API. - -1. Check the host and key placement: `https://pro-api.llama.fi/{YOUR_API_KEY}/...`, not `api.llama.fi` and not `?apikey=`. -2. 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}`. -3. Retry the keyed URL: `https://pro-api.llama.fi/{YOUR_API_KEY}/api/overview/derivatives`. - -**Pro users accessing free endpoints:** Pro API key holders can also call free endpoints on `pro-api.llama.fi` for higher rate limits. Use the exact path mappings below. - ## Free-to-Pro Path Mapping -Pro users: to call free endpoints with higher rate limits, use `https://pro-api.llama.fi/{YOUR_API_KEY}` with the pro path below. +With a key, call these on `https://pro-api.llama.fi/{YOUR_API_KEY}` with the pro path. | Free path | Pro path (pro-api.llama.fi) | Description | |---|---|---| @@ -59,8 +54,8 @@ Pro users: to call free endpoints with higher rate limits, use `https://pro-api. | `/stablecoin/{asset}` | `/stablecoins/stablecoin/{asset}` | Get historical mcap and historical chain distribution of a stablecoin | | `/stablecoinchains` | `/stablecoins/stablecoinchains` | Get current mcap sum of all stablecoins on each chain | | `/stablecoinprices` | `/stablecoins/stablecoinprices` | Get historical prices of all stablecoins | -| `/pools` | `/yields/pools` | Retrieve the latest data for all pools, including enriched information such as predictions | -| `/chart/{pool}` | `/yields/chart/{pool}` | Get historical APY and TVL of a pool | +| `/pools` | `/yields/v1/pools` | Retrieve the latest data for all pools, including enriched information such as predictions | +| `/chart/{pool}` | `/yields/v1/chart/{pool}` | Get historical APY and TVL of a pool | | `/overview/dexs` | `/api/overview/dexs` | List all dexs along with summaries of their volumes and dataType history data | | `/overview/dexs/{chain}` | `/api/overview/dexs/{chain}` | List all dexs along with summaries of their volumes and dataType history data filtering by chain | | `/summary/dexs/{protocol}` | `/api/summary/dexs/{protocol}` | Get summary of dex volume with historical data | diff --git a/scripts/generate-llms.ts b/scripts/generate-llms.ts index 56f8b7aa0fb..69bb73aaa81 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) { @@ -153,27 +160,27 @@ function formatTagName(tag: string): string { } /** - * 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. + * The one auth section, shared by all three files so an agent gets the same rules from whichever it reads. + * 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. Agents also sent the key as ?apikey= and read the 402 from a + * free host as a lapsed plan. Users call the plan "Pro", "API plan" or "pro API", so the rule keys off + * having a key, not the plan name. Links are absolute because agents often read a saved copy of a file. */ -const PRO_AUTH = `## Pro API authentication +const KEY_RULES = `## Have an API key? Use pro-api.llama.fi for every request -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. +If you or your user has a DefiLlama API key, whatever the plan is called ("API plan", "Pro", "pro API"), send every request to \`https://pro-api.llama.fi/{YOUR_API_KEY}/...\`. That includes TVL, prices, stablecoins, yields, volumes and fees, and any fallback or secondary lookup. Use the free hosts only when there is no key. \`\`\` -WRONG https://pro-api.llama.fi/api/overview/derivatives?apikey={YOUR_API_KEY} -RIGHT https://pro-api.llama.fi/{YOUR_API_KEY}/api/overview/derivatives +RIGHT https://pro-api.llama.fi/{YOUR_API_KEY}/coins/prices/current/coingecko:ethereum +WRONG https://coins.llama.fi/prices/current/coingecko:ethereum (free host: ignores the key, rate limited) +WRONG https://pro-api.llama.fi/coins/prices/current/coingecko:ethereum?apikey={YOUR_API_KEY} (key not in the path) \`\`\` -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. - -## Troubleshooting - -A 200 from \`/protocols\` or \`/overview/fees\` on \`api.llama.fi\` does not validate your API key. Those endpoints require no authentication. A 402 from \`api.llama.fi\` does not prove your subscription expired. It means the endpoint needs the Pro API. - -1. Check the host and key placement: \`https://pro-api.llama.fi/{YOUR_API_KEY}/...\`, not \`api.llama.fi\` and not \`?apikey=\`. -2. 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}\`. -3. Retry the keyed URL: \`https://pro-api.llama.fi/{YOUR_API_KEY}/api/overview/derivatives\`.` +- The free hosts (\`api.llama.fi\`, \`coins.llama.fi\`, \`stablecoins.llama.fi\`, \`yields.llama.fi\`) never read a key, so a 429 there means the request belongs on pro-api.llama.fi. A 402 there means the endpoint needs pro-api, not that the plan expired. +- The key goes in the path, right after the host. Headers and \`?apikey=\` are not read: pro-api answers \`500 {"error":"API Key is wrong"}\`. +- Paths on pro-api have a prefix: \`/protocols\` becomes \`/api/protocols\`, \`/prices/current/{coins}\` becomes \`/coins/prices/current/{coins}\`, \`/stablecoins\` becomes \`/stablecoins/stablecoins\`, \`/pools\` becomes \`/yields/v1/pools\`. Every free path is mapped in [llms.txt](https://api-docs.defillama.com/llms.txt), and the pro-only endpoints are in [llms-pro.txt](https://api-docs.defillama.com/llms-pro.txt). +- One key unlocks every endpoint. There are no add-ons or separate keys. +- To check a key, call \`https://pro-api.llama.fi/usage/{YOUR_API_KEY}\` (key at the end, for this endpoint only). It returns \`{"creditsLeft": ...}\`. A 200 from a free host proves nothing, those endpoints need no key.` function generateIndex(freeEndpoints: Endpoint[], proEndpoints: Endpoint[], mappingTable: string): string { const freeGroups = groupByTag(freeEndpoints) @@ -183,6 +190,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. +${KEY_RULES} + ## Important: Free API vs Pro API The Free API and Pro API are entirely separate services. @@ -194,13 +203,9 @@ The Free API and Pro API are entirely separate services. | Rate Limit | Standard | Higher | | Endpoints | ${freeEndpoints.length} | ${proEndpoints.length} exclusive + ${freeEndpoints.length} free with prefix | -${PRO_AUTH} - -**Pro users accessing free endpoints:** Pro API key holders can also call free endpoints on \`pro-api.llama.fi\` for higher rate limits. Use the exact path mappings below. - ## Free-to-Pro Path Mapping -Pro users: to call free endpoints with higher rate limits, use \`https://pro-api.llama.fi/{YOUR_API_KEY}\` with the pro path below. +With a key, call these on \`https://pro-api.llama.fi/{YOUR_API_KEY}\` with the pro path. ${mappingTable} @@ -239,13 +244,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 +282,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,20 +330,21 @@ 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. Each endpoint lists its free base URL and, under it, the URL to use with a key. + +${KEY_RULES}`, 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. -${PRO_AUTH} - -Pro users can also call free endpoints with higher rate limits using the path mappings below. +${KEY_RULES} ## Free Endpoints Available on Pro (Higher Rate Limits) -Use base URL https://pro-api.llama.fi/{YOUR_API_KEY} with the pro path column. +Call these on \`https://pro-api.llama.fi/{YOUR_API_KEY}\` with the pro path. ${mappingTable}`