> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coingecko.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Agents & LLM Apps

> Build AI agents and LLM-powered apps with real-time crypto data from CoinGecko — MCP, SDK function calling, and prompt patterns

<CardGroup cols={2}>
  <Card title="Set up your API key" icon="key" href="/docs/setting-up-your-api-key" horizontal arrow="true" />

  <Card title="Build faster with AI" icon="robot" href="/ai-integration#coding-agents" horizontal arrow="true" />
</CardGroup>

<Note>
  **TL;DR**<br />

  Connect via [MCP](/ai-integration/mcp-server) for zero-code data access, use the [SDK](/docs/sdk) for function calling in custom agents, and query [/simple/price](/reference/simple-price), [/search](/reference/search-data), [/search/trending](/reference/trending-search), and onchain endpoints for real-time context.
</Note>

> Replace `YOUR_API_KEY` in the examples below with your actual key. [Get one here →](https://www.coingecko.com/en/api/pricing)

## 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](/ai-integration/mcp-server).

<Steps>
  <Step title="Connect the MCP server">
    <Tabs>
      <Tab title="Claude Code">
        ```bash theme={null}
        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`.
      </Tab>

      <Tab title="Cursor / IDE">
        Add to `~/.cursor/mcp.json` (or your IDE's MCP config):

        ```json theme={null}
        {
          "mcpServers": {
            "coingecko": {
              "command": "npx",
              "args": ["mcp-remote", "https://mcp.api.coingecko.com/mcp"]
            }
          }
        }
        ```
      </Tab>

      <Tab title="Python (MCP Client)">
        ```python theme={null}
        from mcp import ClientSession
        from mcp.client.streamable_http import streamablehttp_client

        async with streamablehttp_client(
            "https://mcp.api.coingecko.com/mcp"
        ) as (read, write, _):
            async with ClientSession(read, write) as session:
                await session.initialize()
                tools = await session.list_tools()
        ```
      </Tab>
    </Tabs>

    > Full setup for all platforms: [CoinGecko MCP →](/ai-integration/mcp-server) | [MCP Tools →](/ai-integration/mcp-tools)
  </Step>

  <Step title="Add Docs MCP (optional)">
    Let your agent search CoinGecko documentation for endpoint details and parameter info.

    ```bash theme={null}
    claude mcp add --transport http \
      coingecko-docs https://docs.coingecko.com/mcp
    ```

    > [Docs MCP →](/ai-integration/docs-mcp)
  </Step>

  <Step title="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"*
  </Step>
</Steps>

***

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

<Steps>
  <Step title="Install the SDK">
    <CodeGroup>
      ```bash Python theme={null}
      pip install coingecko_sdk
      ```

      ```bash TypeScript theme={null}
      npm install @coingecko/coingecko-typescript
      ```
    </CodeGroup>
  </Step>

  <Step title="Initialize the client">
    <CodeGroup>
      ```python Python theme={null}
      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
      )
      ```

      ```typescript TypeScript theme={null}
      import Coingecko from '@coingecko/coingecko-typescript';

      const client = new Coingecko({
        proAPIKey: process.env['COINGECKO_PRO_API_KEY'],
        environment: 'pro',  // or 'demo' with demoAPIKey
      });
      ```
    </CodeGroup>

    > Full SDK setup: [Python →](/docs/sdk-python) | [TypeScript →](/docs/sdk-typescript)
  </Step>

  <Step title="Define tools for your LLM">
    Map SDK methods to tool definitions your LLM can call. Example tool schema:

    ```json theme={null}
    {
      "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"]
      }
    }
    ```
  </Step>

  <Step title="Execute tool calls">
    When the LLM returns a tool call, execute it against the SDK:

    <CodeGroup>
      ```python Python theme={null}
      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()
      ```

      ```typescript TypeScript theme={null}
      async function executeTool(name: string, args: Record<string, any>) {
        if (name === 'get_crypto_price') {
          return client.simple.price.get(args);
        } else if (name === 'search_coins') {
          return client.search.get(args);
        } else if (name === 'get_trending') {
          return client.search.trending.get();
        }
      }
      ```
    </CodeGroup>

    > All available methods: [TypeScript →](/docs/sdk-typescript-methods) | [Python →](/docs/sdk-python-methods)
  </Step>
</Steps>

***

## Key Endpoints for AI Agents

The most useful endpoints for agent tool definitions — each maps to a common user intent.

| Intent                        | Endpoint                                                              | What it returns                                          |
| ----------------------------- | --------------------------------------------------------------------- | -------------------------------------------------------- |
| "What's the price of X?"      | [/simple/price](/reference/simple-price)                              | Spot prices with optional market cap, volume, 24h change |
| "Find tokens matching Y"      | [/search](/reference/search-data)                                     | Coins, categories, and markets matching a query          |
| "What's trending?"            | [/search/trending](/reference/trending-search)                        | Top trending coins, NFTs, and categories (24h)           |
| "Show me market data"         | [/coins/markets](/reference/coins-markets)                            | Bulk market data — rankings, sparklines, price changes   |
| "Price of this token address" | [/onchain/.../token\_price](/reference/onchain-simple-price)          | Onchain token price by contract address                  |
| "Token info for address"      | [/onchain/.../tokens/\{addr}](/reference/token-data-contract-address) | Token metadata, price, volume, and top pools             |
| "Trending DEX pools"          | [/onchain/.../trending\_pools](/reference/trending-pools-list)        | Hottest liquidity pools across all networks              |

<Tip>
  Use [/search](/reference/search-data) 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.
</Tip>

***

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

<Card title="SDK Prompts" icon="clipboard" href="/ai-integration/sdk-prompts">
  AI prompt rules for generating correct CoinGecko SDK code.
</Card>
