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

# Create API Key

> Generate a new API key with optional webhook URL

Generate a new API key. The full key is only returned once — store it securely. Optionally set a webhook URL at creation time.

## Request Body

<ParamField body="action" type="string" required>
  Must be `generate`.
</ParamField>

<ParamField body="name" type="string" required>
  Descriptive name for the key (e.g., "Production Server", "CI Pipeline"). Max 64 characters.
</ParamField>

<ParamField body="webhook_url" type="string">
  Optional HTTPS URL to receive webhook events. A signing secret is auto-generated when set.
</ParamField>

## Response

<ResponseField name="key" type="string">
  The full API key. **Only shown once.** Format: `mgp_` followed by 40 hex characters.
</ResponseField>

<ResponseField name="id" type="string">
  UUID of the created key. Use this for update/revoke operations.
</ResponseField>

<ResponseField name="name" type="string">
  The key name.
</ResponseField>

<ResponseField name="key_prefix" type="string">
  First 8 characters of the key for identification.
</ResponseField>

<ResponseField name="created_at" type="string">
  ISO 8601 creation timestamp.
</ResponseField>

<ResponseField name="webhook_secret" type="string">
  Signing secret for HMAC verification, or `null` if no webhook URL was set.
</ResponseField>

<Warning>
  The full API key is only returned in this response. Store it immediately — you cannot retrieve it later.
</Warning>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.magpipe.ai/functions/v1/manage-api-keys \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "action": "generate",
      "name": "Production Server",
      "webhook_url": "https://your-server.com/webhook"
    }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch(
    'https://api.magpipe.ai/functions/v1/manage-api-keys',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        action: 'generate',
        name: 'Production Server',
        webhook_url: 'https://your-server.com/webhook',
      }),
    }
  );

  const data = await response.json();
  console.log('API Key (save this!):', data.key);
  console.log('Webhook Secret:', data.webhook_secret);
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://api.magpipe.ai/functions/v1/manage-api-keys',
      headers={
          'Authorization': 'Bearer YOUR_API_KEY',
          'Content-Type': 'application/json',
      },
      json={
          'action': 'generate',
          'name': 'Production Server',
          'webhook_url': 'https://your-server.com/webhook',
      }
  )

  data = response.json()
  print(f"API Key (save this!): {data['key']}")
  print(f"Webhook Secret: {data['webhook_secret']}")
  ```
</RequestExample>

<ResponseExample>
  ```json Success Response theme={null}
  {
    "key": "mgp_fc059e03d5c97cbf328b4a1412c226625e9ae512",
    "id": "fd5afe2f-1747-4ae2-9f41-9e1b3b4307b5",
    "name": "Production Server",
    "key_prefix": "mgp_fc05",
    "created_at": "2026-02-18T10:40:36.561396+00:00",
    "webhook_secret": "whsec_example0000000000000000000000000000000000000000000000000000000"
  }
  ```

  ```json Without Webhook theme={null}
  {
    "key": "mgp_2161ad7e5372924dc39e3cfd3d284d01819411ad",
    "id": "c8e84946-470e-438d-b36d-7aa8cf14b8a1",
    "name": "CI Pipeline",
    "key_prefix": "mgp_2161",
    "created_at": "2026-02-18T10:29:11.887458+00:00",
    "webhook_secret": null
  }
  ```
</ResponseExample>
