# Delete an API

Deleting an API removes it from **APIs** with everything that belongs to it. An API that a gateway serves cannot be deleted. A deleted API cannot be restored.

## Before you begin

Remove the API from every gateway that serves it. An API added to any environment of a gateway counts as served by that gateway.

To see which gateways serve the API, open its **Settings** tab and select **Danger zone**. The **Delete this API** row names them.

To remove the API from a gateway:

1. In the portal, go to [**Agent Gateway**](https://auth.faustine.ai/go?to=%2Fintegrations%2Fagent-gateway) and select the gateway.
2. In the **APIs** tab, select the API.
3. Select **Remove from gateway** and confirm.
4. Repeat in each environment of the gateway that has the API. The environment button in the header switches between them.

Removing an API from a gateway makes its operations disappear from that environment immediately. See [Add an API to a gateway](https://docs.faustine.ai/agent-gateway/add-an-api/).

## Delete the API

To delete an API:

1. In the portal, go to [**APIs**](https://auth.faustine.ai/go?to=%2Fintegrations%2Fapis) and select the API.
2. Select the **Settings** tab, then **Danger zone**.
3. In the **Delete this API** row, check that it reads `Not served by any gateway`. While a gateway serves the API, **Delete API** is disabled.
4. Select **Delete API**.
5. Confirm with **Delete**.

The portal returns to the **APIs** list.

The list has the same action in the menu of each API's row. For an API that a gateway serves, the item reads **Delete (in use)** and is disabled.

## What is deleted

| Deleted | Detail |
| --- | --- |
| Operations and recipes | Including each recipe's revisions. |
| Versions | The draft and every published version. |
| Connections | Endpoints and credential values. |
| Tests | Test plans, suites and their runs. |
| History | The API's analysis and change history. |
| Services and reference repositories | The sources the analysis read. |
| Uploaded code | The ZIP archives of the API and of its services. |

Your repository and your running API are not touched.

**Delete uploaded code**, in the same section, is a different action. It deletes the stored ZIP archive and keeps the API.

## Troubleshooting

| Symptom | Cause | Fix |
| --- | --- | --- |
| **Delete API** is disabled | A gateway serves the API. The row names the gateways. | Remove the API from each of them, in every environment. |
| The dialog shows `This API is used by a gateway` | The API was added to a gateway after the page loaded. | Remove it from the gateway and delete again. |

## Next steps

- [Create an API](https://docs.faustine.ai/apis/create-an-api/): analyze the API again from its code.
- [Versions and updates](https://docs.faustine.ai/apis/versions/): go back to an earlier version without deleting the API.
- [Add an API to a gateway](https://docs.faustine.ai/agent-gateway/add-an-api/): change or remove what a gateway serves.
