> For the complete documentation index, see [llms.txt](https://agpt.co/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://agpt.co/docs/platform/api-and-integrations/api-guide/environments.md).

# Cloud and self-hosted

Point the same integration at AutoGPT Cloud or a self-hosted instance: base URLs, how to check them, and what differs when you host AutoGPT yourself.

AutoGPT Cloud and self-hosted AutoGPT run the same API. An integration only needs to know two things: the instance's base URL and an API key created on that instance. Keep both in configuration, not in code:

```bash
AUTOGPT_API_URL=https://backend.agpt.co/api/v2
AUTOGPT_API_KEY=agpt_...
```

## Base URLs

| Where AutoGPT runs                                                                                             | `AUTOGPT_API_URL`                    |
| -------------------------------------------------------------------------------------------------------------- | ------------------------------------ |
| AutoGPT Cloud                                                                                                  | `https://backend.agpt.co/api/v2`     |
| Self-hosted with Docker Compose ([setup guide](https://agpt.co/docs/platform/self-hosting/getting-started.md)) | `http://localhost:8006/api/v2`       |
| Self-hosted single container ([setup guide](https://agpt.co/docs/platform/self-hosting/single-container.md))   | `http://localhost:3000/_agpt/api/v2` |

For an instance on another machine or domain:

* **Docker Compose:** the API is served by the `rest_server` service on port `8006`. Use the address where that port is reachable, plus `/api/v2`, e.g. `https://autogpt-api.example.com/api/v2` behind a reverse proxy.
* **Single container:** use the container's `AUTOGPT_PUBLIC_URL` plus `/_agpt/api/v2`, e.g. `https://autogpt.example.com/_agpt/api/v2`.

The web app, where you create API keys, is on port `3000` in both self-hosted setups: `http://localhost:3000/settings/api-keys`.

## Check the URL and key

Run this before writing any code:

```bash
curl -s -w "\nHTTP %{http_code}\n" "$AUTOGPT_API_URL/me" -H "X-API-Key: $AUTOGPT_API_KEY"
```

| Result                               | Meaning                                                                                                                                               |
| ------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| `HTTP 200` with your email           | The URL and key are right.                                                                                                                            |
| `HTTP 401`                           | The URL is right, but the key is not valid **on this instance**. Keys from AutoGPT Cloud don't work on a self-hosted instance, and the reverse.       |
| `HTTP 403`                           | The key works but lacks the **Identity** permission. Any other endpoint the key may use proves the URL too.                                           |
| `HTTP 404`                           | Wrong path. Check the table above. If `$AUTOGPT_API_URL/openapi.json` also returns `404`, the instance runs a release from before API v2: upgrade it. |
| `HTTP 429` with `5 requests per 60s` | The request didn't carry a valid key, so it counted as anonymous. Fix the key and wait a minute.                                                      |
| No HTTP status                       | Nothing is listening at that address, or TLS failed.                                                                                                  |

Every instance also serves its own reference for the API version it runs: the OpenAPI spec at `$AUTOGPT_API_URL/openapi.json` and an interactive explorer at `$AUTOGPT_API_URL/docs`.

## What's different on a self-hosted instance

The endpoints, requests and responses are the same. What differs is the account and the environment around them:

| Topic                  | AutoGPT Cloud                                                                              | Self-hosted                                                                                                                                                                                                                                                                                                   |
| ---------------------- | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Accounts and API keys  | Created at platform.agpt.co                                                                | Created in your instance's app. Keys only work on the instance that issued them.                                                                                                                                                                                                                              |
| Billing                | Runs need an active plan and a positive balance, or they fail with `402 payment_required`. | No billing: runs are never refused or charged for, and `GET /credits` returns a fixed placeholder balance.                                                                                                                                                                                                    |
| AI model blocks        | Platform-provided model access is available.                                               | Blocks that call model providers need provider keys configured on the instance, or credentials each user adds. See [AutoPilot on a self-hosted LLM](https://agpt.co/docs/platform/using-ai-services/copilot-local-llm.md) and [Advanced Setup](https://agpt.co/docs/platform/self-hosting/advanced_setup.md). |
| Marketplace            | The public AutoGPT marketplace.                                                            | The instance's own marketplace, separate from AutoGPT Cloud's.                                                                                                                                                                                                                                                |
| Search (`GET /search`) | Indexed.                                                                                   | Uses the instance's own search index. A new instance may return few or no results until it's indexed.                                                                                                                                                                                                         |
| OAuth apps             | Registered by the AutoGPT team.                                                            | Register your own with `poetry run oauth-tool generate-app` in the backend. See [OAuth & SSO](https://agpt.co/docs/platform/api-and-integrations/oauth-guide.md).                                                                                                                                             |
| Share links            | `https://platform.agpt.co/share/...`                                                       | Built from the instance's public URL (`FRONTEND_BASE_URL` with Docker Compose, `AUTOGPT_PUBLIC_URL` in the single container), so set it to an address your readers can open.                                                                                                                                  |
| Rate limits            | As documented.                                                                             | The same limits.                                                                                                                                                                                                                                                                                              |

### Behind a reverse proxy

Authenticated requests are rate-limited per user, so a proxy doesn't affect them. Unauthenticated requests are limited to 5 per minute **per client IP**, and behind a proxy every client can appear to come from the proxy's address and share that one allowance. If you rely on unauthenticated traffic, set `TRUSTED_PROXIES` in the backend's environment to the proxies in front of it, as comma-separated IP addresses or CIDR ranges, so the API reads the client address from `X-Forwarded-For` past them; [Client IP Addresses](https://agpt.co/docs/platform/self-hosting/client-ip.md#limits-on-the-external-api) explains the setting and the deprecated `TRUSTED_PROXY_COUNT` it replaces.

Serve the API over HTTPS whenever it is reachable from another machine. API keys travel in a request header and are as sensitive as a password.

## One integration for both

Read the base URL and key from configuration, and the same code runs against either:

{% tabs %}
{% tab title="Python" %}

```python
import os

API_URL = os.environ.get("AUTOGPT_API_URL", "https://backend.agpt.co/api/v2").rstrip("/")
HEADERS = {"X-API-Key": os.environ["AUTOGPT_API_KEY"]}
```

{% endtab %}

{% tab title="TypeScript" %}

```typescript
const API_URL = (process.env.AUTOGPT_API_URL ?? "https://backend.agpt.co/api/v2").replace(/\/$/, "");
const HEADERS = { "X-API-Key": process.env.AUTOGPT_API_KEY! };
```

{% endtab %}
{% endtabs %}

Things that legitimately vary by instance, and should be read at runtime rather than hard-coded: block IDs other than the core ones, agent and graph IDs, credential IDs, and marketplace agents. A graph JSON that uses a block missing from the instance fails with `400 bad_request` when you create it.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://agpt.co/docs/platform/api-and-integrations/api-guide/environments.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
