Skip to main content

Set up your API key

Build faster with AI

TL;DR
Connect via MCP for zero-code data access, use the SDK for function calling in custom agents, and query /simple/price, /search, /search/trending, and onchain endpoints for real-time context.
Replace YOUR_API_KEY in the examples below with your actual key. Get one here →

Option 1: MCP Server (Zero-Code)

The fastest way to give an AI agent access to CoinGecko data. No SDK code needed — the agent calls tools directly through the Model Context Protocol.
1

Connect the MCP server

claude mcp add --transport http \
  coingecko https://mcp.api.coingecko.com/mcp
For higher limits, use https://mcp.pro-api.coingecko.com/mcp and authenticate via /mcp.
Full setup for all platforms: CoinGecko MCP → | MCP Tools →
2

Add Docs MCP (optional)

Let your agent search CoinGecko documentation for endpoint details and parameter info.
claude mcp add --transport http \
  coingecko-docs https://docs.coingecko.com/mcp
Docs MCP →
3

Ask your agent

The agent now has access to 85+ CoinGecko tools. Try:
  • “What’s the current price of Bitcoin, Ethereum, and Solana?”
  • “Show me the top 10 trending pools on Base”
  • “Find all tokens related to ‘AI’ and get their market data”

Option 2: SDK Function Calling (Custom Agents)

For custom AI agents where you control the tool definitions and execution flow — use the SDK as the function calling backend.
1

Install the SDK

pip install coingecko_sdk
2

Initialize the client

import os
from coingecko_sdk import Coingecko

client = Coingecko(
    pro_api_key=os.environ.get("COINGECKO_PRO_API_KEY"),
    environment="pro",  # or "demo" with demo_api_key
)
Full SDK setup: Python → | TypeScript →
3

Define tools for your LLM

Map SDK methods to tool definitions your LLM can call. Example tool schema:
{
  "name": "get_crypto_price",
  "description": "Get current prices for one or more cryptocurrencies",
  "parameters": {
    "type": "object",
    "properties": {
      "ids": {
        "type": "string",
        "description": "Comma-separated CoinGecko coin IDs (e.g. bitcoin,ethereum)"
      },
      "vs_currencies": {
        "type": "string",
        "description": "Comma-separated target currencies (e.g. usd,eur)"
      }
    },
    "required": ["ids", "vs_currencies"]
  }
}
4

Execute tool calls

When the LLM returns a tool call, execute it against the SDK:
def execute_tool(name, args):
    if name == "get_crypto_price":
        return client.simple.price.get(**args)
    elif name == "search_coins":
        return client.search.get(**args)
    elif name == "get_trending":
        return client.search.trending.get()
All available methods: TypeScript → | Python →

Key Endpoints for AI Agents

The most useful endpoints for agent tool definitions — each maps to a common user intent.
IntentEndpointWhat it returns
”What’s the price of X?”/simple/priceSpot prices with optional market cap, volume, 24h change
”Find tokens matching Y”/searchCoins, categories, and markets matching a query
”What’s trending?”/search/trendingTop trending coins, NFTs, and categories (24h)
“Show me market data”/coins/marketsBulk market data — rankings, sparklines, price changes
”Price of this token address”/onchain/…/token_priceOnchain token price by contract address
”Token info for address”/onchain/…/tokens/{addr}Token metadata, price, volume, and top pools
”Trending DEX pools”/onchain/…/trending_poolsHottest liquidity pools across all networks
Use /search as your agent’s resolver — when a user mentions a coin by name or symbol, search first to get the correct CoinGecko ID, then pass it to other endpoints.

Prompt Engineering Tips

  • Always resolve IDs first. Coin names are ambiguous — use /search or /coins/list to resolve to a CoinGecko ID before querying price or market data.
  • Include units in responses. When returning prices, always include the currency (e.g. “$67,432 USD” not just “67432”).
  • Handle missing data. Not all coins have market cap, volume, or contract addresses. Instruct your agent to check for null fields.
  • Rate limit awareness. Tell your agent to batch requests where possible (e.g. ids=bitcoin,ethereum,solana in one call instead of three).

SDK Prompts

AI prompt rules for generating correct CoinGecko SDK code.