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

# Authentication

> Authenticate requests with your API key.

Every API request needs an API key in the `Authorization` header.

```text theme={null}
Authorization: Bearer $GETIMG_API_KEY
```

## Get your API key

Create and manage API keys in the [developer settings](https://getimg.ai/app/developer/api-keys).

## Use your key

<CodeGroup>
  ```javascript Node.js theme={null}
  import GetimgAI from "getimg-ai";

  const client = new GetimgAI({
    apiKey: process.env.GETIMG_API_KEY, // default, can be omitted
  });

  const result = await client.images.generate({
    model: "seedream-5-lite",
    prompt: "A sunset over the ocean",
  });
  ```

  ```python Python theme={null}
  import os
  from getimg import GetimgAI

  client = GetimgAI(
      api_key=os.environ.get("GETIMG_API_KEY"),  # default, can be omitted
  )

  result = client.images.generate(
      model="seedream-5-lite",
      prompt="A sunset over the ocean",
  )
  ```

  ```bash cURL theme={null}
  curl -X POST https://api.getimg.ai/v2/images/generations \
    -H "Authorization: Bearer $GETIMG_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"model": "seedream-5-lite", "prompt": "A sunset over the ocean"}'
  ```
</CodeGroup>

## Security best practices

* Store API keys in environment variables, not source code.
* Add `.env` files to `.gitignore`.
* Revoke compromised API keys in [developer settings](https://getimg.ai/app/developer/api-keys) and create replacements.
* Use separate API keys for development and production.

## Authentication errors

Missing, malformed, or invalid keys return `401` with error code `invalid_api_key`.

```json theme={null}
{
  "error": {
    "message": "Incorrect API key provided. You can manage your API keys at https://getimg.ai/app/developer/api-keys",
    "type": "invalid_request_error",
    "param": null,
    "code": "invalid_api_key",
    "doc_url": "https://docs.getimg.ai/guides/authentication"
  }
}
```

See [Errors](/guides/errors) for error handling and retry guidance.
