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

# Getting Started

> Set up AI Gateway in minutes and start tracking your AI usage

# Getting Started with AI Gateway

Follow these steps to start routing your AI requests through the LeanMCP AI Gateway.

<Tip>
  **Already have a LeanMCP account?** Skip straight to [Step 3: Generate an API Key](#step-3-generate-an-api-key).
</Tip>

## Prerequisites

<Note>
  You need credits on your LeanMCP account to use the AI Gateway. Credits are used to cover the cost of AI provider requests plus a small gateway fee.
</Note>

<AccordionGroup>
  <Accordion title="New to LeanMCP? Set up your account first (Steps 1 & 2)">
    ## Step 1: Create an Account

    1. Go to [leanmcp.com](https://leanmcp.com)
    2. Sign up with your email or GitHub account
    3. Complete the onboarding process

    <Frame>
      <img src="https://mintlify.s3.us-west-1.amazonaws.com/leanmcp/images/ai-gateway-signup.png" alt="Sign up for LeanMCP" />
    </Frame>

    ## Step 2: Purchase Credits

    1. Navigate to **Settings** > **Billing** in your dashboard
    2. Select a credit package or set up auto-recharge
    3. Complete the payment

    <Info>
      Credits are used at approximately the same rate as direct API calls, plus a small fee for gateway services (logging, security scanning, etc.).
    </Info>
  </Accordion>
</AccordionGroup>

## Step 3: Generate an API Key

1. Go to **Settings** > **API Keys**
2. Click **Create New API Key**
3. Give your key a descriptive name (e.g., "Windsurf Development")
4. Copy and save your API key securely

<Warning>
  Your API key is shown only once. Store it securely - you'll need it to authenticate requests.
</Warning>

## Step 4: Configure Your Application

Replace your AI provider's base URL and API key with the gateway endpoint:

<Tabs>
  <Tab title="OpenAI">
    ```typescript theme={null}
    import OpenAI from 'openai';

    const client = new OpenAI({
      baseURL: 'https://aigateway.leanmcp.com/v1/openai',
      apiKey: 'your-leanmcp-api-key',
    });
    ```
  </Tab>

  <Tab title="Anthropic">
    ```typescript theme={null}
    import Anthropic from '@anthropic-ai/sdk';

    const client = new Anthropic({
      baseURL: 'https://aigateway.leanmcp.com/v1/anthropic',
      apiKey: 'your-leanmcp-api-key',
    });
    ```
  </Tab>

  <Tab title="Cursor / Windsurf">
    In your IDE settings, update the API configuration:

    **Base URL:** `https://aigateway.leanmcp.com/v1/openai`

    **API Key:** Your LeanMCP API key
  </Tab>
</Tabs>

## Step 5: Verify It's Working

Make a test request and check your dashboard:

```typescript theme={null}
const response = await client.chat.completions.create({
  model: 'gpt-5.2',
  messages: [{ role: 'user', content: 'Hello!' }],
});

console.log(response.choices[0].message.content);
```

1. Open [app.leanmcp.com/observability](https://app.leanmcp.com/observability)
2. You should see your test request appear within a few seconds

<Frame>
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/leanmcp/images/ai-gateway-logs.png" alt="AI Gateway Logs" />
</Frame>

<Tip>
  ✓ **Saw your request in the logs? You're connected.** → [Open app.leanmcp.com/observability](https://app.leanmcp.com/observability) to start monitoring.
</Tip>

## What's Next?

<CardGroup cols={2}>
  <Card title="View Request Logs" icon="list" href="/ai-gateway/observability">
    See all your AI requests and responses
  </Card>

  <Card title="Set Up Security Rules" icon="shield" href="/ai-gateway/security">
    Block sensitive data and malicious requests
  </Card>

  <Card title="Track Token Usage" icon="chart-bar" href="/ai-gateway/token-optimization">
    Monitor costs and optimize spending
  </Card>

  <Card title="Full Integration Guide" icon="code" href="/guides/ai-gateway">
    Code examples for all providers
  </Card>
</CardGroup>

***

<Card title="Ready? Open your Observability Dashboard →" icon="eye" href="https://app.leanmcp.com/observability" color="#ff6b35">
  View your first logged AI request at **app.leanmcp.com/observability**
</Card>
