API Directory › 🔗 Blockchain & Web3 › The Graph
No authHTTPSCORS

The Graph API

Query indexed blockchain data using GraphQL subgraphs.

Auth
No auth needed
HTTPS
Yes
CORS
Yes
Open The Graph docs ↗

What it does

The Graph is a decentralised protocol for indexing blockchain data. Developers publish subgraphs (open-source indexing definitions) and anyone queries them with GraphQL — getting structured, filterable, historical data from a protocol without scanning the chain yourself.

Base URL

https://gateway.thegraph.com/api/{API_KEY}/subgraphs/id/{SUBGRAPH_ID}

Authentication

Create an API key in Subgraph Studio. Queries are GraphQL POSTs to the decentralised network gateway with your key in the path. (The old free hosted service at api.thegraph.com/subgraphs/name/… has been sunset — migrate to the network.)

Code examples

curl
curl -s -X POST "https://gateway.thegraph.com/api/$GRAPH_KEY/subgraphs/id/$SUBGRAPH_ID" \
  -H "Content-Type: application/json" \
  -d '{"query":"{ pairs(first:3, orderBy:reserveUSD, orderDirection:desc){ id reserveUSD } }"}'
Python
import requests

q = """{ tokens(first: 5, orderBy: tradeVolumeUSD, orderDirection: desc) {
  symbol tradeVolumeUSD } }"""
r = requests.post(f"https://gateway.thegraph.com/api/{KEY}/subgraphs/id/{SUBGRAPH_ID}",
                  json={"query": q}, timeout=20)
for t in r.json()["data"]["tokens"]:
    print(t["symbol"], t["tradeVolumeUSD"])

Rate limits & quotas

The network bills per query in GRT, but there is a free monthly allowance (on the order of 100,000 queries/month) on the Studio free plan. Queries have a complexity/time budget; deeply nested or unbounded queries are rejected. Rate limiting and HTTP 429 apply once you exceed your plan.

Key response fields

data.<entity>[]GraphQL results — entity names and fields are defined by the specific subgraph’s schema
errors[]GraphQL errors (query invalid against the schema, or indexing lag)
_meta.block.numberThe block the subgraph is indexed up to — check for lag
(pagination)Use first + skip, or where: { id_gt: lastId } for large scans

Common errors

401 / 403Missing or invalid API key, or the key has no budget.
errors: 'no indexers found'The subgraph isn’t served on the network — it may be unpublished or deprecated.
400GraphQL query doesn’t match the subgraph schema — introspect it first.
(stale data)Check _meta.block.number — an indexer can be behind the chain head.

When to use it (and alternatives)

The right tool when a protocol you care about (a DEX, lending market, NFT marketplace, DAO) has a subgraph — you get exactly its domain entities, queryable and historical. For generic wallet/token data across chains without a subgraph, use Covalent or Bitquery.

FAQ

The hosted service URL I had stopped working — why?

The Graph sunset the centralised hosted service. Subgraphs now live on the decentralised network; query them via gateway.thegraph.com/api/{key}/subgraphs/id/{id} with a Studio API key.

How do I find a subgraph's schema?

Run a GraphQL introspection query against the endpoint, or look it up on The Graph Explorer, which shows each subgraph’s entities and a query playground.

Is it really free?

There is a free query allowance per month on the Studio free plan. Beyond that you add a payment method and pay per query (fractions of a cent), settled in GRT.

New to APIs?

Short guides for working with this API — and any other.

🛠️ Handy LarzOS tools

Free tools to help you work with this API.

JSON Formatter

Related Blockchain & Web3 APIs

← Back

More Blockchain & Web3 APIs · All 196 APIs