Skip to content

Commit 61b059f

Browse files
authored
add llms generator and split (#13)
* add llms generator and split * add response hint
1 parent 8086d27 commit 61b059f

5 files changed

Lines changed: 1102 additions & 2146 deletions

File tree

examples/web/src/llms-middleware.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@
44
* Usage with Express:
55
* ```ts
66
* import { llmsMiddleware } from './llms-middleware'
7-
* app.use(llmsMiddleware(llmsContent))
8-
* ```
9-
*
10-
* Usage with Hono:
11-
* ```ts
12-
* import { isAIUserAgent } from './llms-middleware'
13-
* app.use('/', async (c, next) => {
14-
* if (isAIUserAgent(c.req.header('user-agent'))) {
15-
* return c.text(llmsContent)
16-
* }
17-
* await next()
18-
* })
7+
* app.use(llmsMiddleware({
8+
* 'llms.txt': llmsIndex,
9+
* 'llms-free.txt': llmsFree,
10+
* 'llms-pro.txt': llmsPro,
11+
* }))
1912
* ```
2013
*/
2114

@@ -48,20 +41,27 @@ export function isAIUserAgent(userAgent: string | undefined): boolean {
4841

4942
export type LlmsMiddleware = (req: any, res: any, next: () => void) => void
5043

51-
export function llmsMiddleware(llmsContent: string): LlmsMiddleware {
44+
export type LlmsFiles = {
45+
'llms.txt': string
46+
'llms-free.txt': string
47+
'llms-pro.txt': string
48+
}
49+
50+
export function llmsMiddleware(files: LlmsFiles): LlmsMiddleware {
5251
return (req, res, next) => {
5352
const userAgent = req.headers['user-agent']
53+
const filename = req.url?.replace(/^\//, '') as keyof LlmsFiles
5454

55-
if (req.url === '/llms.txt') {
55+
if (filename in files) {
5656
res.setHeader('Content-Type', 'text/plain; charset=utf-8')
57-
res.end(llmsContent)
57+
res.end(files[filename])
5858
return
5959
}
6060

6161
if (req.url === '/' && isAIUserAgent(userAgent)) {
6262
res.setHeader('Content-Type', 'text/plain; charset=utf-8')
6363
res.setHeader('X-Served-As', 'llms.txt')
64-
res.end(llmsContent)
64+
res.end(files['llms.txt'])
6565
return
6666
}
6767

llms-free.txt

Lines changed: 292 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
# DefiLlama Free API
2+
3+
> Free API — no authentication required. All endpoints below use base URL https://api.llama.fi
4+
5+
**Base URL for ALL endpoints below:** `https://api.llama.fi`
6+
7+
## TVL
8+
9+
### GET /protocols
10+
**Base URL:** `https://api.llama.fi`
11+
List all protocols on defillama along with their tvl
12+
Returns: array of {id, name, symbol, category, chains, tvl, chainTvls, change_1d, change_7d}
13+
14+
### GET /protocol/{protocol}
15+
**Base URL:** `https://api.llama.fi`
16+
Get historical TVL of a protocol and breakdowns by token and chain
17+
18+
**Parameters:**
19+
- `protocol` (path, string, required) — protocol slug Example: `aave`
20+
Returns: {id, name, symbol, category, chains, currentChainTvls, chainTvls}
21+
22+
### GET /v2/historicalChainTvl
23+
**Base URL:** `https://api.llama.fi`
24+
Get historical TVL (excludes liquid staking and double counted tvl) of DeFi on all chains
25+
Returns: array of {date, tvl}
26+
27+
### GET /v2/historicalChainTvl/{chain}
28+
**Base URL:** `https://api.llama.fi`
29+
Get historical TVL (excludes liquid staking and double counted tvl) of a chain
30+
31+
**Parameters:**
32+
- `chain` (path, string, required) — chain slug, you can get these from /chains or the chains property on /protocols Example: `Ethereum`
33+
Returns: array of {date, tvl}
34+
35+
### GET /tvl/{protocol}
36+
**Base URL:** `https://api.llama.fi`
37+
Simplified endpoint to get current TVL of a protocol
38+
39+
**Parameters:**
40+
- `protocol` (path, string, required) — protocol slug Example: `uniswap`
41+
Returns: number
42+
43+
### GET /v2/chains
44+
**Base URL:** `https://api.llama.fi`
45+
Get current TVL of all chains
46+
Returns: array of {gecko_id, tvl, tokenSymbol, cmcId, name, chainId}
47+
48+
---
49+
50+
## Coins & Prices
51+
52+
### GET /prices/current/{coins}
53+
**Base URL:** `https://api.llama.fi`
54+
Get current prices of tokens by contract address
55+
56+
**Parameters:**
57+
- `coins` (path, string, required) — set of comma-separated tokens defined as {chain}:{address} Example: `ethereum:0xdF574c24545E5FfEcb9a659c229253D4111d87e1,coingecko:ethereum,bsc:0x762539b45a1dcce3d36d080f74d1aed37844b878,ethereum:0xdB25f211AB05b1c97D595516F45794528a807ad8`
58+
- `searchWidth` (query, string, optional) — time range on either side to find price data, defaults to 6 hours Example: `4h`
59+
Returns: {coins}
60+
61+
### GET /prices/historical/{timestamp}/{coins}
62+
**Base URL:** `https://api.llama.fi`
63+
Get historical prices of tokens by contract address
64+
65+
**Parameters:**
66+
- `coins` (path, string, required) — set of comma-separated tokens defined as {chain}:{address} Example: `ethereum:0xdF574c24545E5FfEcb9a659c229253D4111d87e1,coingecko:ethereum,bsc:0x762539b45a1dcce3d36d080f74d1aed37844b878,ethereum:0xdB25f211AB05b1c97D595516F45794528a807ad8`
67+
- `timestamp` (path, number, required) — UNIX timestamp of time when you want historical prices Example: `1648680149`
68+
- `searchWidth` (query, string, optional) — time range on either side to find price data, defaults to 6 hours Example: `4h`
69+
Returns: {coins}
70+
71+
### GET /batchHistorical
72+
**Base URL:** `https://api.llama.fi`
73+
Get historical prices for multiple tokens at multiple different timestamps
74+
75+
**Parameters:**
76+
- `coins` (query, string, required) — object where keys are coins in the form {chain}:{address}, and values are arrays of requested timestamps Example: `{"avax:0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e": [1666876743, 1666862343], "coingecko:ethereum": [1666869543, 1666862343]}
77+
`
78+
- `searchWidth` (query, string, optional) — time range on either side to find price data, defaults to 6 hours Example: `600`
79+
Returns: {coins}
80+
81+
### GET /chart/{coins}
82+
**Base URL:** `https://api.llama.fi`
83+
Get token prices at regular time intervals
84+
85+
**Parameters:**
86+
- `coins` (path, string, required) — set of comma-separated tokens defined as {chain}:{address} Example: `ethereum:0xdF574c24545E5FfEcb9a659c229253D4111d87e1,coingecko:ethereum,bsc:0x762539b45a1dcce3d36d080f74d1aed37844b878,ethereum:0xdB25f211AB05b1c97D595516F45794528a807ad8`
87+
- `start` (query, number, optional) — unix timestamp of earliest data point requested Example: `1664364537`
88+
- `end` (query, number, optional) — unix timestamp of latest data point requested
89+
- `span` (query, number, optional) — number of data points returned, defaults to 0 Example: `10`
90+
- `period` (query, string, optional) — duration between data points, defaults to 24 hours Example: `2d`
91+
- `searchWidth` (query, string, optional) — time range on either side to find price data, defaults to 10% of period Example: `600`
92+
Returns: {coins}
93+
94+
### GET /percentage/{coins}
95+
**Base URL:** `https://api.llama.fi`
96+
Get percentage change in price over time
97+
98+
**Parameters:**
99+
- `coins` (path, string, required) — set of comma-separated tokens defined as {chain}:{address} Example: `ethereum:0xdF574c24545E5FfEcb9a659c229253D4111d87e1,coingecko:ethereum,bsc:0x762539b45a1dcce3d36d080f74d1aed37844b878,ethereum:0xdB25f211AB05b1c97D595516F45794528a807ad8`
100+
- `timestamp` (query, number, optional) — timestamp of data point requested, defaults to time now Example: `1664364537`
101+
- `lookForward` (query, boolean, optional) — whether you want the duration after your given timestamp or not, defaults to false (looking back) Example: `false`
102+
- `period` (query, string, optional) — duration between data points, defaults to 24 hours Example: `3w`
103+
Returns: {coins}
104+
105+
### GET /prices/first/{coins}
106+
**Base URL:** `https://api.llama.fi`
107+
Get earliest timestamp price record for coins
108+
109+
**Parameters:**
110+
- `coins` (path, string, required) — set of comma-separated tokens defined as {chain}:{address} Example: `ethereum:0xdF574c24545E5FfEcb9a659c229253D4111d87e1,coingecko:ethereum,bsc:0x762539b45a1dcce3d36d080f74d1aed37844b878,ethereum:0xdB25f211AB05b1c97D595516F45794528a807ad8`
111+
Returns: {coins}
112+
113+
### GET /block/{chain}/{timestamp}
114+
**Base URL:** `https://api.llama.fi`
115+
Get the closest block to a timestamp
116+
117+
**Parameters:**
118+
- `chain` (path, string, required) — Chain which you want to get the block from Example: `ethereum`
119+
- `timestamp` (path, integer, required) — UNIX timestamp of the block you are searching for Example: `1603964988`
120+
Returns: {height, timestamp}
121+
122+
---
123+
124+
## Stablecoins
125+
126+
### GET /stablecoins
127+
**Base URL:** `https://api.llama.fi`
128+
List all stablecoins along with their circulating amounts
129+
130+
**Parameters:**
131+
- `includePrices` (query, boolean, optional) — set whether to include current stablecoin prices Example: `true`
132+
Returns: {peggedAssets}
133+
134+
### GET /stablecoincharts/all
135+
**Base URL:** `https://api.llama.fi`
136+
Get historical mcap sum of all stablecoins
137+
138+
**Parameters:**
139+
- `stablecoin` (query, integer, optional) — stablecoin ID, you can get these from /stablecoins Example: `1`
140+
Returns: array of {date, totalCirculating}
141+
142+
### GET /stablecoincharts/{chain}
143+
**Base URL:** `https://api.llama.fi`
144+
Get historical mcap sum of all stablecoins in a chain
145+
146+
**Parameters:**
147+
- `chain` (path, string, required) — chain slug, you can get these from /chains or the chains property on /protocols Example: `Ethereum`
148+
- `stablecoin` (query, integer, optional) — stablecoin ID, you can get these from /stablecoins Example: `1`
149+
Returns: array of {date, totalCirculating}
150+
151+
### GET /stablecoin/{asset}
152+
**Base URL:** `https://api.llama.fi`
153+
Get historical mcap and historical chain distribution of a stablecoin
154+
155+
**Parameters:**
156+
- `asset` (path, integer, required) — stablecoin ID, you can get these from /stablecoins Example: `1`
157+
Returns: {id, name, symbol, totalCirculating, chainCirculating}
158+
159+
### GET /stablecoinchains
160+
**Base URL:** `https://api.llama.fi`
161+
Get current mcap sum of all stablecoins on each chain
162+
Returns: array of {name, totalCirculating}
163+
164+
### GET /stablecoinprices
165+
**Base URL:** `https://api.llama.fi`
166+
Get historical prices of all stablecoins
167+
Returns: array of {date, prices}
168+
169+
---
170+
171+
## Yields & APY
172+
173+
### GET /pools
174+
**Base URL:** `https://api.llama.fi`
175+
Retrieve the latest data for all pools, including enriched information such as predictions
176+
Returns: {status, data}
177+
178+
### GET /chart/{pool}
179+
**Base URL:** `https://api.llama.fi`
180+
Get historical APY and TVL of a pool
181+
182+
**Parameters:**
183+
- `pool` (path, string, required) — pool id, can be retrieved from /pools (property is called pool) Example: `747c1d2a-c668-4682-b9f9-296708a3dd90`
184+
Returns: {status, data}
185+
186+
---
187+
188+
## DEX Volumes
189+
190+
### GET /overview/dexs
191+
**Base URL:** `https://api.llama.fi`
192+
List all dexs along with summaries of their volumes and dataType history data
193+
194+
**Parameters:**
195+
- `excludeTotalDataChart` (query, boolean, required) — true to exclude aggregated chart from response Example: `true`
196+
- `excludeTotalDataChartBreakdown` (query, boolean, required) — true to exclude broken down chart from response Example: `true`
197+
Returns: {protocols, totalDataChart, allChains}
198+
199+
### GET /overview/dexs/{chain}
200+
**Base URL:** `https://api.llama.fi`
201+
List all dexs along with summaries of their volumes and dataType history data filtering by chain
202+
203+
**Parameters:**
204+
- `chain` (path, string, required) — chain name, list of all supported chains can be found under allChains attribute in /overview/dexs response Example: `ethereum`
205+
- `excludeTotalDataChart` (query, boolean, required) — true to exclude aggregated chart from response Example: `true`
206+
- `excludeTotalDataChartBreakdown` (query, boolean, required) — true to exclude broken down chart from response Example: `true`
207+
Returns: {protocols, totalDataChart}
208+
209+
### GET /summary/dexs/{protocol}
210+
**Base URL:** `https://api.llama.fi`
211+
Get summary of dex volume with historical data
212+
213+
**Parameters:**
214+
- `protocol` (path, string, required) — protocol slug Example: `uniswap`
215+
- `excludeTotalDataChart` (query, boolean, required) — true to exclude aggregated chart from response Example: `true`
216+
- `excludeTotalDataChartBreakdown` (query, boolean, required) — true to exclude broken down chart from response Example: `true`
217+
Returns: {name, total24h, totalAllTime, totalDataChart, totalDataChartBreakdown, chains}
218+
219+
### GET /overview/options
220+
**Base URL:** `https://api.llama.fi`
221+
List all options dexs along with summaries of their volumes and dataType history data
222+
223+
**Parameters:**
224+
- `excludeTotalDataChart` (query, boolean, required) — true to exclude aggregated chart from response Example: `true`
225+
- `excludeTotalDataChartBreakdown` (query, boolean, required) — true to exclude broken down chart from response Example: `true`
226+
- `dataType` (query, string, optional) — Desired data type, dailyNotionalVolume by default. (one of: dailyPremiumVolume, dailyNotionalVolume) Example: `dailyPremiumVolume`
227+
Returns: {protocols, totalDataChart}
228+
229+
### GET /overview/options/{chain}
230+
**Base URL:** `https://api.llama.fi`
231+
List all options dexs along with summaries of their volumes and dataType history data filtering by chain
232+
233+
**Parameters:**
234+
- `chain` (path, string, required) — chain name, list of all supported chains can be found under allChains attribute in /overview/options response Example: `ethereum`
235+
- `excludeTotalDataChart` (query, boolean, required) — true to exclude aggregated chart from response Example: `true`
236+
- `excludeTotalDataChartBreakdown` (query, boolean, required) — true to exclude broken down chart from response Example: `true`
237+
- `dataType` (query, string, optional) — Desired data type, dailyNotionalVolume by default. (one of: dailyPremiumVolume, dailyNotionalVolume) Example: `dailyPremiumVolume`
238+
239+
### GET /summary/options/{protocol}
240+
**Base URL:** `https://api.llama.fi`
241+
Get summary of options dex volume with historical data
242+
243+
**Parameters:**
244+
- `protocol` (path, string, required) — protocol slug Example: `derive`
245+
- `dataType` (query, string, optional) — Desired data type, dailyNotionalVolume by default. (one of: dailyPremiumVolume, dailyNotionalVolume) Example: `dailyPremiumVolume`
246+
247+
---
248+
249+
## Perpetuals & Open Interest
250+
251+
### GET /overview/open-interest
252+
**Base URL:** `https://api.llama.fi`
253+
List all open interest dex exchanges along with summaries of their open interest
254+
255+
**Parameters:**
256+
- `excludeTotalDataChart` (query, boolean, required) — true to exclude aggregated chart from response Example: `true`
257+
- `excludeTotalDataChartBreakdown` (query, boolean, required) — true to exclude broken down chart from response Example: `true`
258+
Returns: {protocols, totalDataChart, allChains}
259+
260+
---
261+
262+
## Fees & Revenue
263+
264+
### GET /overview/fees
265+
**Base URL:** `https://api.llama.fi`
266+
List all protocols along with summaries of their fees and revenue and dataType history data
267+
268+
**Parameters:**
269+
- `excludeTotalDataChart` (query, boolean, required) — true to exclude aggregated chart from response Example: `true`
270+
- `excludeTotalDataChartBreakdown` (query, boolean, required) — true to exclude broken down chart from response Example: `true`
271+
- `dataType` (query, string, optional) — Desired data type, dailyFees by default. (one of: dailyFees, dailyRevenue, dailyHoldersRevenue) Example: `dailyFees`
272+
Returns: {protocols, totalDataChart, totalDataChartBreakdown}
273+
274+
### GET /overview/fees/{chain}
275+
**Base URL:** `https://api.llama.fi`
276+
List all protocols along with summaries of their fees and revenue and dataType history data by chain
277+
278+
**Parameters:**
279+
- `chain` (path, string, required) — chain name, list of all supported chains can be found under allChains attribute in /overview/fees response Example: `ethereum`
280+
- `excludeTotalDataChart` (query, boolean, required) — true to exclude aggregated chart from response Example: `true`
281+
- `excludeTotalDataChartBreakdown` (query, boolean, required) — true to exclude broken down chart from response Example: `true`
282+
- `dataType` (query, string, optional) — Desired data type, dailyFees by default. (one of: dailyFees, dailyRevenue, dailyHoldersRevenue) Example: `dailyFees`
283+
Returns: {protocols, totalDataChart, totalDataChartBreakdown}
284+
285+
### GET /summary/fees/{protocol}
286+
**Base URL:** `https://api.llama.fi`
287+
Get summary of protocol fees and revenue with historical data
288+
289+
**Parameters:**
290+
- `protocol` (path, string, required) — protocol slug Example: `derive`
291+
- `dataType` (query, string, optional) — Desired data type, dailyFees by default. (one of: dailyFees, dailyRevenue, dailyHoldersRevenue) Example: `dailyFees`
292+
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}

0 commit comments

Comments
 (0)