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

# Getting started with API v2

> Use the SiteGPT Agent API v2 to manage chatbots, knowledge, conversations, account data, and team operations.

API v2 is the recommended SiteGPT API for new integrations, AI agents, and CLI-backed automation. It uses scoped bearer tokens that look like `sgpt_xxxxxxxxx` and mirrors the customer-facing dashboard permissions.

<Info>
  If you are using older `/api/v0` endpoints, switch the API Reference version selector to **v0 Legacy**.
</Info>

## Base URL

Use this base URL for API v2:

```text theme={null}
https://sitegpt.ai/api/v2
```

Example:

```bash theme={null}
curl https://sitegpt.ai/api/v2/me \
  -H "Authorization: Bearer sgpt_xxxxxxxxx"
```

## Authentication

API v2 uses scoped SiteGPT API tokens:

```bash theme={null}
Authorization: Bearer sgpt_xxxxxxxxx
```

You can get a token in two ways:

1. Create a token from the SiteGPT dashboard under **Agents**.
2. Use OAuth device login from the SiteGPT CLI or an agent-compatible client.

For CLI login and local AI agents, SiteGPT uses OAuth Device Authorization Grant with this public client ID:

```text theme={null}
client_id=sitegpt-cli
```

See [API v2 authentication](/api-reference/v2/authentication) for token creation, OAuth device login, scopes, and security notes.

## Response shape

API v2 responses use an `ok` field.

Successful responses:

```json theme={null}
{
  "ok": true,
  "data": {},
  "meta": {
    "requestId": "req-id"
  }
}
```

Error responses:

```json theme={null}
{
  "ok": false,
  "error": {
    "code": "TOKEN_SCOPE_NOT_ALLOWED",
    "message": "Token does not have the required scope"
  },
  "meta": {
    "requestId": "req-id"
  }
}
```

## OpenAPI

The machine-readable OpenAPI document is available at:

```text theme={null}
https://sitegpt.ai/api/v2/openapi.json
```

Use the endpoint reference in this version of the docs for the full list of supported API v2 routes, request bodies, query parameters, and response examples.

## Discovery for agents

Most developers do not need these endpoints directly. They are public metadata endpoints for AI agents and tools that discover API authentication automatically:

```text theme={null}
https://sitegpt.ai/.well-known/oauth-authorization-server
https://sitegpt.ai/.well-known/oauth-protected-resource
https://sitegpt.ai/.well-known/oauth-protected-resource/api/v2
```

## Recommended first calls

Verify the token:

```bash theme={null}
curl https://sitegpt.ai/api/v2/me \
  -H "Authorization: Bearer sgpt_xxxxxxxxx"
```

List accessible chatbots:

```bash theme={null}
curl https://sitegpt.ai/api/v2/chatbots \
  -H "Authorization: Bearer sgpt_xxxxxxxxx"
```

Then use the endpoint reference for chatbot creation, knowledge ingestion, conversations, settings, members, leads, billing reads, and account operations.
