Loading...
Loading...
DefiLlama API integration for DeFi analytics - TVL, stablecoin yields, vault/APY ranking, protocol revenue, fees, DEX volume, chain flows, bridges, and treasury data. Best for DeFi research, stablecoin farming, yield strategy screening, and protocol/chain market intelligence.
npx skill4agent add starchild-ai-agent/official-skills defillama| API | Base URL | Auth |
|---|---|---|
| Free API | | None (no key needed) |
| Pro API | | Key in path |
| Bridge API | | None |
Key rule: Usefor all free endpoints (TVL, chains, DEX, fees, prices). Usehttps://api.llama.fiONLY for pro endpoints (yields, derivatives, emissions). Env var:https://pro-api.llama.fi/{API_KEY}— used in pro URL path, NOT as HTTP header.DEFILLAMA_API_KEY
api.llama.fi| Task | Endpoint | Example |
|---|---|---|
| TVL Top N protocols | | Sort by |
| Single protocol detail | | e.g. |
| Chain TVL history | | |
| DEX volumes | | |
| Protocol fees | | |
| All chains TVL | | Sum |
⚠️ Pro endpoints (,/yields/*, etc.) require/emissionsin the URL path.DEFILLAMA_API_KEY
fake-defillama-key-12345DEFILLAMA_API_KEYPROXY_HOSTPROXY_PORTHTTP_PROXYHTTPS_PROXYimport os
import requests
host = os.getenv("PROXY_HOST")
port = os.getenv("PROXY_PORT")
session = requests.Session()
if host and port:
if ":" in host and not host.startswith("["):
host = f"[{host}]" # IPv6-safe
proxy = f"http://{host}:{port}"
session.proxies.update({"http": proxy, "https": proxy})
# Free endpoint (no key needed):
r_free = session.get("https://api.llama.fi/protocols", timeout=25)
print("Free:", r_free.status_code)
# Pro endpoint (key in URL path):
api_key = os.environ["DEFILLAMA_API_KEY"]
r_pro = session.get(f"https://pro-api.llama.fi/{api_key}/yields/pools", timeout=25)
print("Pro:", r_pro.status_code)set -a && source .env && set +a
python3 - << 'PY'
import os, requests
s = requests.Session()
host, port = os.getenv('PROXY_HOST'), os.getenv('PROXY_PORT')
if host and port:
if ':' in host and not host.startswith('['):
host = f'[{host}]'
p = f'http://{host}:{port}'
s.proxies.update({'http': p, 'https': p})
# Free endpoint
r1 = s.get('https://api.llama.fi/protocols', timeout=25)
print('free /protocols:', r1.status_code)
# Pro endpoint
k = os.environ['DEFILLAMA_API_KEY']
r2 = s.get(f'https://pro-api.llama.fi/{k}/yields/pools', timeout=25)
print('pro /yields/pools:', r2.status_code)
PY# All protocols with TVL
GET /protocols
# Single protocol detail
GET /protocol/{slug}
# Chain TVL
GET /v2/chains
GET /v2/historicalChainTvl/{chain}# Current prices (chain:address format)
GET /coins/prices/current/{coins}
# Historical
GET /coins/prices/historical/{timestamp}/{coins}
# Chart data
GET /coins/chart/{coins}?period=30dGET /yields/pools # All yield pools
GET /yields/chart/{pool} # Pool history
GET /yields/poolsBorrow # Borrow rates
GET /yields/perps # Perp funding
GET /yields/lsdRates # LSD ratesGET /overview/dexs?excludeChart=true # DEX volumes (recommended)
GET /overview/dexs/{chain}?excludeChart=true # Chain DEX
GET /summary/dexs/{protocol} # Protocol detail
GET /overview/options?excludeChart=true # Options
GET /overview/derivatives?excludeChart=true # Derivatives (Pro)GET /overview/fees?excludeChart=true # All fees/revenue (recommended)
GET /overview/fees/{chain}?excludeChart=true # Chain fees
GET /summary/fees/{protocol} # Protocol fees
# dataType: dailyFees | dailyRevenue | dailyHoldersRevenue# Base: https://bridges.llama.fi
GET /bridges # All bridges
GET /bridge/{id} # Bridge detail
GET /bridgevolume/{chain} # Volume by chain
GET /transactions/{id} # Bridge txsGET /dat/institutions # All institutions
GET /dat/institutions/{symbol} # e.g., MSTR;; See scripts/defillama.bb for full implementation
(require '[defillama :as dl])
;; TVL
(dl/protocols)
(dl/protocol "aave")
(dl/chain-tvl "Ethereum")
;; Prices
(dl/price "ethereum:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48")
(dl/price-chart "coingecko:ethereum" {:period "30d"})
;; Yields
(dl/yield-pools)
(dl/pool-chart "747c1d2a-c668-4682-b9f9-296708a3dd90")
;; Volumes
(dl/dex-overview)
(dl/dex-protocol "uniswap")
;; Fees
(dl/fees-overview)
(dl/fees-protocol "hyperliquid")/protocols/protocol/{slug}/tvl/{slug}/v2/chains/v2/historicalChainTvl/coins/prices/*/coins/chart/*/overview/dexs/overview/options/overview/fees/summary/fees/*/yields/*/overview/derivatives/tokenProtocols/{symbol}/inflows/{protocol}/{timestamp}/chainAssets/emissions/emission/{protocol}/categories/forks/oracles/entities/treasuries/hacks/raises/etfs/*/dat/*{"id": "2269", "name": "Aave", "tvl": 5200000000, "chains": ["Ethereum"]}{"coins": {"ethereum:0x...": {"price": 0.999, "symbol": "USDC", "confidence": 0.99}}}{"pool": "uuid", "chain": "Ethereum", "project": "aave-v3", "apy": 3.5, "tvlUsd": 1500000000}aptos-agentexa-search$X.XXB$XXXMXX.X%+X.X%-X.X%$%BM| # | Protocol | TVL | Chains |
|---|--------------|-----|-----------|
| 1 | Aave V3 | $24.7B | Ethereum, Arbitrum || Pool | APY | TVL | Risk |
|---------|-----|-----|---------|
| USDC | 5.2% | $500M | ✅ Low risk || Metric | Value |
|------------|-----------|
| Total TVL | $96B |
| DEX 24h volume | $5.7B |
| Fees 24h | $49M |✅ Low risk⚠️ Medium risk🔴 High risk?excludeChart=trueGET /overview/dexs?excludeChart=true # DEX volumes (much faster)
GET /overview/fees?excludeChart=true # Fee data (much faster)https://pro-api.llama.fi/protocolshttps://api.llama.fi/protocolspro-api.llama.fihttps://pro-api.llama.fi/yields/poolshttps://pro-api.llama.fi/{DEFILLAMA_API_KEY}/yields/poolsexcludeChart=true/overview/dexs?excludeChart=truevalid = [p for p in protocols if isinstance(p.get('tvl'), (int, float)) and p['tvl'] > 0]stablecoins.llama.fipool/yields/pools"747c1d2a-c668-4682-b9f9-296708a3dd90"/yields/chart/{pool}stablecoin == truetvlUsd >= 50_000_000apy220ilRisk == "no"exposure == "single"r = requests.get("https://api.llama.fi/protocols")
protocols = r.json()
top10 = sorted([p for p in protocols if p.get('tvl',0) > 0], key=lambda x: x['tvl'], reverse=True)[:10]
# Output: markdown table with | # | Protocol | TVL | Chain |r1 = requests.get("https://api.llama.fi/v2/historicalChainTvl/Ethereum")
r2 = requests.get("https://api.llama.fi/v2/historicalChainTvl/Solana")
# Filter last 30d: [d for d in r1.json() if d['date'] >= time.time() - 30*86400]
# Output: | Chain | TVL 30d ago | TVL today | Change % |r = requests.get(f"https://pro-api.llama.fi/{API_KEY}/yields/pools")
raw = r.json()
pools = raw.get('data', raw) if isinstance(raw, dict) else raw
safe = [p for p in pools
if p.get('stablecoin') is True
and (p.get('tvlUsd') or 0) >= 50_000_000
and (p.get('apy') or 0) >= 2
and (p.get('apy') or 0) <= 20
and p.get('ilRisk') == 'no']
top = sorted(safe, key=lambda x: x.get('apy', 0), reverse=True)[:10]
# Output: | Project | Chain | Symbol | APY | TVL | Risk |chains = requests.get("https://api.llama.fi/v2/chains").json()
dexs = requests.get("https://api.llama.fi/overview/dexs?excludeChart=true").json()
fees = requests.get("https://api.llama.fi/overview/fees?excludeChart=true").json()
# total_tvl = sum(c['tvl'] for c in chains if isinstance(c.get('tvl'), (int,float)))
# Output: snapshot table with TVL, DEX 24h vol, Fee 24hr1 = requests.get("https://api.llama.fi/protocols") # find protocol with big change_1d
r2 = requests.get(f"https://api.llama.fi/protocol/{slug}") # get chainTvls detail
# Output: | Hypothesis | Explanation | How to verify | (table + step-by-step verification)# Stablecoins overview (separate from pro-api)
GET https://stablecoins.llama.fi/stablecoins?includePrices=true
# Chain-specific stablecoin data
GET https://stablecoins.llama.fi/stablecoincharts/{chain}
# chain = "Ethereum", "Solana", "BSC", etc.
# All chains stablecoin summary
GET https://stablecoins.llama.fi/stablecoinchainsstablecoincharts/{chain}/v2/historicalChainTvl/{chain}/yields/pools{"data": [...], "status": "success"}r = session.get(f"https://pro-api.llama.fi/{api_key}/yields/pools")
raw = r.json()
pools = raw.get('data', raw) if isinstance(raw, dict) else raw
# Filter example: TVL > $50M and APY > 0
filtered = [p for p in pools if p.get('tvlUsd', 0) >= 50_000_000 and (p.get('apy') or 0) > 0]| Field | Type | Description |
|---|---|---|
| UUID string | Unique pool identifier |
| string | Chain name |
| string | Protocol name |
| string | Token pair (e.g. "USDC-WETH") |
| number | TVL in USD |
| number | Current APY % |
| number | Base APY (lending/trading fees) |
| number | Incentive APY (token rewards) |
| "yes"/"no" | Impermanent loss risk |
| "single"/"multi" | Single vs multi-asset exposure |
| number | APY change past 7 days |