
DefiLlama Data API: Extract Structured JSON in 2026
Learn how to build a reliable data pipeline to get structured defillama data via API. Use schema-based JSON extraction for ticker, price, and market cap.
AlterLab handles this automatically — scrape any URL with one API call. No infrastructure required.
Try it freeTL;DR: To get structured DefiLlama data via API, use the AlterLab Extract API to send a URL and a JSON schema. This returns validated, typed JSON containing specific finance metrics like ticker, price, and market cap, bypassing the need for manual HTML parsing.
Disclaimer: This guide covers extracting publicly accessible data. Always review a site's robots.txt and Terms of Service before scraping.
Why use DefiLlama data?
DefiLlama is the industry standard for decentralized finance (DeFi) analytics. For data engineers and AI developers, accessing this information in a machine-readable format is critical for several high-stakes use cases:
- AI Training & RAG: Feeding real-time TVL (Total Value Locked) or protocol metrics into Large Language Models to power financial AI agents.
- Automated Analytics: Building dashboards that track protocol growth, volume shifts, and liquidity movements across different chains.
- Competitive Intelligence: Monitoring market cap fluctuations and volume trends to identify emerging protocols in the DeFi ecosystem.
Extract structured finance data from DefiLlama
What data can you extract?
When building a data pipeline for finance, you need more than raw HTML. You need specific, typed fields. Using a data API approach, you can target any publicly available metric on DefiLlama, including:
- ticker: The unique identifier for the asset or protocol.
- price: The current market price in USD.
- change_percent: The 24-hour price movement percentage.
- volume: The 24-hour trading volume.
- market_cap: The total market capitalization.
By defining these in a schema, you ensure your downstream database receives clean data every time.
The extraction approach
Traditionally, developers attempted to get this data using standard HTTP libraries (like requests in Python) combined with HTML parsers (like BeautifulSoup).
This approach is extremely fragile. Finance websites frequently update their DOM structure, class names, and nesting to optimize for performance or change their UI. A single class name change in a React component can break your entire data pipeline. Furthermore, modern finance sites use complex obfuscation and anti-bot measures that standard libraries cannot navigate.
A data API solves this by moving the complexity from your code to the infrastructure. Instead of writing logic to find a <div> with a specific class, you simply describe the data you want. The engine handles the rendering, the proxy rotation, and the parsing, returning only the clean JSON you requested.
Quick start with AlterLab Extract API
To begin, you'll need to follow our Getting started guide. Once you have your API key, you can use the extract endpoint to turn any public DefiLlama URL into a structured object.
Python Implementation
The Python SDK makes it easy to define a schema and receive typed data.
import alterlab
client = alterlab.Client("YOUR_API_KEY")
schema = {
"type": "object",
"properties": {
"ticker": {
"type": "string",
"description": "The asset ticker symbol"
},
"price": {
"type": "string",
"description": "Current price in USD"
},
"change_percent": {
"type": "string",
"description": "24h percentage change"
},
"volume": {
"type": "string",
"description": "24h trading volume"
},
"market_cap": {
"type": "string",
"description": "Total market cap"
}
}
}
result = client.extract(
url="https://defillama.com/protocols/example",
schema=schema,
)
print(result.data)cURL Implementation
If you prefer working in the terminal or via shell scripts, use a simple POST request.
curl -X POST https://api.alterlab.io/v1/extract \
-H "X-API-Key: YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://defillama.com/protocols/example",
"schema": {
"type": "object",
"properties": {
"ticker": {"type": "string"},
"price": {"type": "string"},
"change_percent": {"type": "string"}
}
}
}'Define your schema
The power of the Extract API docs lies in the schema definition. You aren't just asking for "the price"; you are defining a contract.
When you provide a JSON schema, AlterLab uses LLM-powered extraction to map the visual elements of the page to your specific keys. If the website changes "Price: $1,200" to "$1,200 USD", a standard scraper breaks. A schema-based data API understands that both represent the same data point.
Handle pagination and scale
For production-grade pipelines, you rarely extract one page at a time. You likely need to monitor hundreds of protocols or thousands of tokens.
When scaling, you should implement an asynchronous job pattern. Instead of waiting for a synchronous response, you can dispatch multiple extraction requests and handle them as they complete. This is essential for maintaining high throughput without hitting local resource limits.
For large-scale operations, you can estimate your costs before running heavy batches. Use the estimation endpoint to preview the cost of a call before committing.
import alterlab
import asyncio
client = alterlab.Client("YOUR_API_KEY")
async def get_protocol_data(url, schema):
# Using async for high-volume extraction
return await client.extract_async(url=url, schema=schema)
async def main():
schema = {"type": "object", "properties": {"ticker": {"type": "string"}}}
urls = ["https://defillama.com/protocols/a", "https://defillama.com/protocols/b"]
tasks = [get_protocol_data(url, schema) for url in urls]
results = await asyncio.gather(*tasks)
for r in results:
print(r.data)
asyncio.run(main())As your volume grows, keep an eye on your AlterLab pricing. We offer a transparent, pay-for-what-you-use model. There are no hidden fees or massive upfront commitments. You can set spend limits on your API keys to ensure your budget stays within your project's parameters.
Key takeaways
- Avoid fragile parsing: Stop writing regex and CSS selectors for finance sites.
- Use schemas: Define your data contract upfront to get reliable, typed JSON.
- Scale with async: Use asynchronous patterns to build high-throughput data pipelines.
- Automate everything: Combine extraction with scheduling to create self-updating datasets.
Hit reply if you have questions.
AlterLab // Web Data, Simplified.
Was this article helpful?
Frequently Asked Questions
Related Articles

How to Scrape Lonely Planet Data: Complete Guide for 2026
Learn how to scrape Lonely Planet travel data with Python and Node.js using AlterLab’s API, handling anti-bot measures and extracting structured JSON.
Herald Blog Service

How to Give Your AI Agent Access to VentureBeat Data
Learn how to connect your AI agent to VentureBeat for real-time tech intelligence. Use AlterLab to bypass anti-bot measures and get structured JSON data.
Herald Blog Service

Clearbit Data API: Extract Structured JSON in 2026
Learn how to build a high-performance clearbit data api pipeline to extract structured JSON from public pages using AlterLab's Extract API and JSON schemas.
Herald Blog Service
Popular Posts
Recommended

How to Scrape AliExpress: Complete Guide for 2026

Why Your Headless Browser Gets Detected (and How to Fix It)

AlterLab vs Firecrawl: In-Depth Review with Benchmarks & Code Examples

How to Scrape Twitter/X Data: Complete Guide for 2026

How to Scrape Cloudflare-Protected Sites in 2026
Newsletter
Scraping insights and API tips. No spam.
Recommended Reading

How to Scrape AliExpress: Complete Guide for 2026

Why Your Headless Browser Gets Detected (and How to Fix It)

AlterLab vs Firecrawl: In-Depth Review with Benchmarks & Code Examples

How to Scrape Twitter/X Data: Complete Guide for 2026

How to Scrape Cloudflare-Protected Sites in 2026
Stay in the Loop
Get scraping insights, API tips, and platform updates. No spam — we only send when we have something worth reading.
Explore AlterLab
Web Scraping API Resources
Part of the Web Scraping API Documentation cluster
Complete API reference with 5-tier auto-escalation — Curl to challenge resolution.
Pillar pageConfigure Tier 4 browser rendering for SPAs and dynamic content.
Scrape pages behind login using session management.
Real success rates and cost data across all 5 tiers.
MCP Server, Python SDK, and Firecrawl-compatible API for AI agent workflows.