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

# Authentication

> Secure your API requests with API keys

All API requests to genui.sh require authentication using an API key.

## Getting Your API Key

1. Sign in to your [genui.sh dashboard](https://genui.sh/dashboard)
2. Navigate to **Settings** > **API Keys**
3. Click **Create New Key**
4. Copy and securely store your API key

<Warning>
  API keys are only shown once when created. If you lose your key, you'll need to generate a new one.
</Warning>

## Using Your API Key

Include your API key in the `Authorization` header of all requests:

```
Authorization: Bearer YOUR_API_KEY
```

<CodeGroup>
  ```bash curl theme={null}
  curl -X GET https://genui.sh/api/artifacts \
    -H "Authorization: Bearer genui_abc123..."
  ```

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

  API_KEY = os.environ.get("GENUI_API_KEY")

  response = requests.get(
      "https://genui.sh/api/artifacts",
      headers={"Authorization": f"Bearer {API_KEY}"}
  )
  ```

  ```javascript JavaScript theme={null}
  const API_KEY = process.env.GENUI_API_KEY;

  const response = await fetch('https://genui.sh/api/artifacts', {
    headers: {
      'Authorization': `Bearer ${API_KEY}`
    }
  });
  ```

  ```go Go theme={null}
  apiKey := os.Getenv("GENUI_API_KEY")

  req, _ := http.NewRequest("GET", "https://genui.sh/api/artifacts", nil)
  req.Header.Set("Authorization", "Bearer "+apiKey)
  ```

  ```ruby Ruby theme={null}
  api_key = ENV['GENUI_API_KEY']

  request = Net::HTTP::Get.new(uri)
  request['Authorization'] = "Bearer #{api_key}"
  ```

  ```rust Rust theme={null}
  let api_key = std::env::var("GENUI_API_KEY")?;

  let response = client
      .get("https://genui.sh/api/artifacts")
      .header("Authorization", format!("Bearer {}", api_key))
      .send()
      .await?;
  ```

  ```csharp .NET theme={null}
  var apiKey = Environment.GetEnvironmentVariable("GENUI_API_KEY");

  client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
  var response = await client.GetAsync("https://genui.sh/api/artifacts");
  ```
</CodeGroup>

## Best Practices

<AccordionGroup>
  <Accordion title="Use environment variables">
    Never hardcode API keys in your source code. Use environment variables instead:

    ```bash theme={null}
    export GENUI_API_KEY=genui_your_key_here
    ```
  </Accordion>

  <Accordion title="Rotate keys regularly">
    Generate new API keys periodically and revoke old ones from the dashboard.
  </Accordion>

  <Accordion title="Use separate keys for different environments">
    Create separate API keys for development, staging, and production environments.
  </Accordion>

  <Accordion title="Monitor usage">
    Check your dashboard regularly to monitor API usage and detect any anomalies.
  </Accordion>
</AccordionGroup>

## Error Responses

If authentication fails, you'll receive one of these responses:

| Status Code | Error          | Description                                       |
| ----------- | -------------- | ------------------------------------------------- |
| 401         | `unauthorized` | Missing or invalid API key                        |
| 403         | `forbidden`    | API key doesn't have permission for this resource |
| 429         | `rate_limited` | Too many requests, slow down                      |

Example error response:

```json theme={null}
{
  "error": {
    "code": "unauthorized",
    "message": "Invalid API key provided"
  }
}
```

## Rate Limits

API requests are rate limited based on your plan:

| Plan       | Requests per minute |
| ---------- | ------------------- |
| Free       | 60                  |
| Pro        | 600                 |
| Enterprise | Custom              |

Rate limit headers are included in all responses:

```
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 45
X-RateLimit-Reset: 1705320000
```
