# API Key Setup

## API Key Setup

All ChainGPT API products require an API key for authentication. This page walks through obtaining a key, configuring it for use with the plugin, and managing your credit balance.

### Getting an API key

1. Visit [app.chaingpt.org](https://app.chaingpt.org) and connect a crypto wallet to create an account.
2. Navigate to **API Keys** and click **Create New Secret Key**.
3. Copy the key immediately — it is only displayed once.
4. Store it securely using an environment variable or secret manager.

### Configuring the key

#### Environment variable (recommended)

Set the `CHAINGPT_API_KEY` environment variable in your shell:

```bash
export CHAINGPT_API_KEY="your-key-here"
```

Add this to your `.bashrc`, `.zshrc`, or `.env` file so it persists across sessions.

#### Plugin installs

If you installed via `/plugin install`, the MCP server reads `CHAINGPT_API_KEY` from your environment automatically via the `.mcp.json` configuration:

```json
{
  "mcpServers": {
    "chaingpt": {
      "command": "node",
      "args": ["${CLAUDE_PLUGIN_ROOT}/mcp-server/dist/index.js"],
      "env": {
        "CHAINGPT_API_KEY": "${CHAINGPT_API_KEY}"
      }
    }
  }
}
```

#### Manual installs

If you installed via git clone, set the key in your `.claude/settings.json` MCP server configuration (see Installation).

### Loading credits

API calls consume credits. To load credits:

1. Visit [app.chaingpt.org/addcredits](https://app.chaingpt.org/addcredits).
2. Choose a payment method: crypto (USDT, USDC, ETH, BNB, TRX, $CGPT) or credit card.
3. 1,000 credits costs $10 USD (1 credit = $0.01).
4. Pay with $CGPT tokens for a **15% bonus** on every purchase.

Credits never expire.

### Verifying your setup

Test that your key works by asking Claude to check your credit balance (requires the MCP server):&#x20;

```
"Check my ChainGPT credit balance"
```

Or test manually with cURL:

```bash
curl -s -o /dev/null -w "%{http_code}" \
  -X GET "https://api.chaingpt.org/nft/get-chains?testNet=false" \
  -H "Authorization: Bearer $CHAINGPT_API_KEY"
```

A `200` response means your key is valid. A `401` means the key is invalid or expired — regenerate it from the dashboard.

### Common issues

**Key not found:** Ensure there are no trailing whitespace characters or newlines in the key value. Check with: `echo -n $CHAINGPT_API_KEY | wc -c`

**Wrong header format:** The Authorization header must use the `Bearer` prefix: `Authorization: Bearer <key>`. Not `Token <key>` or just the raw key.

**Insufficient credits:** HTTP 402 or 403 responses indicate your credit balance is too low. Top up at [app.chaingpt.org/addcredits](https://app.chaingpt.org/addcredits).

### API authentication details

All ChainGPT API products share the same authentication mechanism:

| Setting      | Value                                |
| ------------ | ------------------------------------ |
| Base URL     | `https://api.chaingpt.org`           |
| Auth header  | `Authorization: Bearer <API_KEY>`    |
| Rate limit   | 200 requests/minute per key          |
| Content type | `application/json` for POST requests |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.chaingpt.org/dev-docs-b2b-saas-api-and-sdk/chaingpt-claude-skill-and-plugin/getting-started/api-key-setup.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
