
DefiLlama Data API: Extract Structured JSON in 2026
DefiLlama Data API: Extract Structured JSON in 2026 TL;DR: To get structured DefiLlama data via API, use the AlterLab Extract API to send a URL and a JSON...
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.
from alterlab import AlterLabSync
client = AlterLabSync("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.scrape(
url="https://defillama.com/protocols/example",
extraction_schema=schema,
)
print(result["filtered_content"])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.
from alterlab import AlterLab
import asyncio
client = AlterLab("YOUR_API_KEY")
async def get_protocol_data(url, schema):
# Using async for high-volume extraction
return await client.scrape(url=url, extraction_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

Oxylabs Alternative: Practical Developer Guide for Web Scraping Pipelines
Build reliable scraping pipelines with anti-bot handling, auto-escalation, and monitoring using a practical AltLab-compatible solution. Follow the 3-step setup, integrate with your existing workflow, and control costs at $0.0002 per request.
Herald Blog Service

Python aiohttp vs. httpx for High-Throughput Web Scraping
A benchmark‑driven comparison of aiohttp and httpx for asynchronous scraping, with concrete numbers, code snippets, and guidance on when to choose each library.
Herald Blog Service

MCP Servers Explained: How AI Tools Access the Real-Time Web in 2026
Learn how Model Context Protocol servers enable AI agents to fetch live data via scraping APIs, with architecture, code examples, and best practices for 2026.
Herald Blog Service
Popular Posts
Recommended

Selenium Bot Detection: Why You Get Flagged and How to Fix It

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

Playwright Stealth and Anti-Bot Techniques for RAG Pipelines

Mastering Playwright Stealth for Agentic Web Workflows

How to Bypass Cloudflare Bot Protection with Puppeteer in 2026
Newsletter
Scraping insights and API tips. No spam.
Recommended Reading

Selenium Bot Detection: Why You Get Flagged and How to Fix It

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

Playwright Stealth and Anti-Bot Techniques for RAG Pipelines

Mastering Playwright Stealth for Agentic Web Workflows

How to Bypass Cloudflare Bot Protection with Puppeteer 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.