> ## 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 Your API Key

> Create a LeanMCP API key to use the AI Gateway

# Getting Your API Key

To use the LeanMCP AI Gateway, you need an API key. This key authenticates your requests and tracks your usage.

## Prerequisites

<Note>
  You need credits on your LeanMCP account before using the AI Gateway. Purchase credits at [app.leanmcp.com/billing](https://app.leanmcp.com/billing) first.
</Note>

## Creating an API Key

<Steps>
  <Step title="Go to API Keys Page">
    Navigate to [app.leanmcp.com/api-keys](https://app.leanmcp.com/api-keys)

    <Frame>
      <img src="https://mintlify.s3.us-west-1.amazonaws.com/leanmcp/images/ai-gateway-api-keys-page.png" alt="API Keys page" />
    </Frame>
  </Step>

  <Step title="Click Create New Key">
    Click the **Create API Key** button in the top right corner.
  </Step>

  <Step title="Configure Your Key">
    Fill in the details:

    * **Name**: A descriptive name (e.g., "Windsurf Development", "Production App")
    * **Permissions**: Select **SDK** permissions for AI Gateway access

    <Frame>
      <img src="https://mintlify.s3.us-west-1.amazonaws.com/leanmcp/images/ai-gateway-create-key.png" alt="Create API key modal" />
    </Frame>
  </Step>

  <Step title="Copy and Save">
    Your API key will be displayed **only once**. Copy it immediately and store it securely.

    <Warning>
      API keys are shown only at creation time. If you lose it, you'll need to create a new one.
    </Warning>
  </Step>
</Steps>

## API Key Format

LeanMCP API keys are prefixed with `leanmcp_` for easy identification:

```
leanmcp_859fc75e29e90aaf85d3a1eb55803c902995a0b796ef3b93cdac445692be53ea
```

## Using Your API Key

Once you have your API key, use it in place of your AI provider's API key:

<Tabs>
  <Tab title="Environment Variable">
    ```bash theme={null}
    export LEANMCP_API_KEY="leanmcp_your_key_here"
    ```
  </Tab>

  <Tab title="In Code">
    ```typescript theme={null}
    const client = new OpenAI({
      baseURL: 'https://aigateway.leanmcp.com/v1/openai',
      apiKey: 'leanmcp_your_key_here',
    });
    ```
  </Tab>

  <Tab title="In IDE Settings">
    Paste your API key in the API Key field of your IDE's AI configuration.
  </Tab>
</Tabs>

## Managing API Keys

### View All Keys

Go to [app.leanmcp.com/api-keys](https://app.leanmcp.com/api-keys) to see all your API keys:

* Creation date
* Last used
* Usage statistics

### Delete a Key

To revoke an API key:

1. Go to the API Keys page
2. Find the key you want to delete
3. Click the **Delete** button
4. Confirm deletion

<Warning>
  Deleting an API key immediately stops all requests using that key. Make sure to update your applications before deleting.
</Warning>

### Rotate Keys

For security, we recommend rotating your API keys periodically:

1. Create a new API key
2. Update your applications to use the new key
3. Verify everything works
4. Delete the old key

## Best Practices

<AccordionGroup>
  <Accordion title="Use separate keys for different environments">
    Create separate API keys for development, staging, and production. This makes it easier to track usage and rotate keys without affecting all environments.
  </Accordion>

  <Accordion title="Never commit API keys to version control">
    Use environment variables or secret management tools. Add `.env` files to your `.gitignore`.
  </Accordion>

  <Accordion title="Monitor your usage">
    Check the API Keys page regularly to monitor usage and detect any unusual activity.
  </Accordion>

  <Accordion title="Set up billing alerts">
    Configure alerts in your dashboard to be notified when you're approaching credit limits.
  </Accordion>
</AccordionGroup>

## Next Steps

Now that you have your API key, set up the AI Gateway in your preferred tool:

<CardGroup cols={2}>
  <Card title="Cursor" icon="text-cursor" href="/ai-gateway/cursor">
    Configure Cursor IDE
  </Card>

  <Card title="Windsurf" icon="wind" href="/ai-gateway/windsurf">
    Configure Windsurf IDE
  </Card>

  <Card title="Raycast" icon="bolt" href="/ai-gateway/raycast">
    Configure Raycast AI
  </Card>

  <Card title="OpenCode" icon="terminal" href="/ai-gateway/opencode">
    Configure OpenCode CLI
  </Card>

  <Card title="SDK Integration" icon="code" href="/ai-gateway/sdk-integration">
    Use in your applications
  </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>
