# Generating an API key

API keys allow you to authenticate with P0's Management API and integrate P0 into your infrastructure-as-code workflows. You need an API key to:

* Use the [Management API](/p0-management/management-api.md) to programmatically configure P0 settings
* Install and manage P0 using the [P0 Terraform Provider](https://github.com/p0-security/terraform-provider-p0)

## Prerequisites

You must have the **Owner** role in your P0 organization to generate API keys.

## Generate an API key

1. Navigate to **P0 Management** in the P0 dashboard sidebar.
2. Expand the **API Keys** section.
3. Click **Create a new API key**.
4. Enter a descriptive name for the key (for example, "Terraform CI/CD" or "Management API").
5. Click **Submit**.
6. Copy the API key immediately.

<figure><img src="/files/ndbts4t1D27RsUXgNKi1" alt="The API Keys section in P0 Management showing the Create a new API key dialog" width="563"><figcaption></figcaption></figure>

{% hint style="warning" %}
**Copy your API key now.** The API key is only displayed once at creation time. You cannot retrieve it later. If you lose the key, you must generate a new one.
{% endhint %}

## Using the API key

### With the Management API

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

```bash
curl -H "Authorization: Bearer YOUR_API_KEY" \
  https://api.p0.app/o/{orgId}/...
```

### With the Terraform provider

Configure the P0 Terraform provider with your API key:

```hcl
provider "p0" {
  api_key = var.p0_api_key
}
```

For more information, see the [P0 Terraform Provider documentation](https://github.com/p0-security/terraform-provider-p0).

## Best practices

* **Use descriptive names** for your API keys to identify their purpose.
* **Rotate keys regularly** as part of your security hygiene.
* **Store keys securely** using a secrets manager or environment variables. Never commit API keys to version control.
* **Delete unused keys** to minimize your attack surface.

## Related

* [Management API](/p0-management/management-api.md)
* [Role-Based Access Control](/p0-management/role-based-access-control.md)


---

# 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.p0.dev/p0-management/generating-an-api-key.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.
