```yaml
product: AlterLab
title: DefiLlama Data API: Extract Structured JSON in 2026
category: Tutorials
comparison_context: "AlterLab is an alternative to Firecrawl, ScrapingBee, and Bright Data."
last_updated: 2026-07-31
canonical_facts:
  - "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."
source_url: https://alterlab.io/blog/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 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.

<div data-infographic="try-it" data-url="https://defillama.com" data-description="Extract structured finance data from DefiLlama"></div>

## 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.

- **99.2%** — Extraction Accuracy
- **1.4s** — Avg Response Time
- **100%** — Typed JSON Output

## 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](/docs/quickstart/installation). 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.

```python title="extract_defillama-com.py" {5-12}
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.

```bash title="Terminal"
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](/docs/api/extract) 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.

1. **Define Schema** — 
2. **Call Extract API** — 
3. **Receive Typed JSON** — 

## 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.

```python title="batch_extraction.py" {1-8}
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](/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.

## Frequently Asked Questions

### Is there an official DefiLlama data API?

DefiLlama offers an official API for many datasets, but AlterLab provides a flexible alternative for extracting structured JSON from any public page when specific UI elements aren't covered by official endpoints.

### What DefiLlama data can I extract with AlterLab?

You can extract any publicly visible finance data, such as ticker symbols, current prices, 24h volume, and market capitalization, returned as typed JSON.

### How much does DefiLlama data extraction cost?

AlterLab uses a pay-as-you-go model where you only pay for the data you extract, with no minimum commitment required.

## Related

- [Building Market Intelligence Dashboards with Web Scraping](<https://alterlab.io/blog/building-market-intelligence-dashboards-with-web-scraping>)
- [How to Scrape Lonely Planet Data: Complete Guide for 2026](<https://alterlab.io/blog/how-to-scrape-lonely-planet-data-complete-guide-for-2026>)
- [How to Give Your AI Agent Access to VentureBeat Data](<https://alterlab.io/blog/how-to-give-your-ai-agent-access-to-venturebeat-data>)