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

# Scripts API

> Base URL, authentication, scopes, limits, and webhooks for the Scripts API.

The **Scripts API** provides HTTP access to your scripts: code, branches, commits, backend functions, collections, webhooks, AI, and Studio (versions, users, configuration).

## Base URL

```text theme={null}
https://ucsyxzpdbnuyehizezvb.supabase.co/functions/v1/doglytdc-scripts-api
```

The complete, machine-readable index is at [`/scripts.json`](https://ucsyxzpdbnuyehizezvb.supabase.co/functions/v1/doglytdc-scripts-api/scripts.json) (no authentication required).

## Authentication

Send `Authorization: Bearer <token>` with every request.

| Credential | Prefix | How to obtain it |
| - | - | - |
| `script_token` | `dts_…` | **Painel Dev** (Dev panel) › API › **Gerar token** (Generate token). Valid only for that script, with all scopes. |
| `oauth2` | — | OAuth2 Hub with PKCE: [https://doglytdc.dev/oauth2/authorize](https://doglytdc.dev/oauth2/authorize) (same flow as /v1/hub). Request the scopes below. |
| `session` | — | DoglyTdc session (used by the panel). Routes marked as session accept only this credential. |

> [!WARNING]
>
> Never put the token inside the script distributed to users. It grants access to the script's code and backend.

## Scopes

| Scope | What it allows |
| - | - |
| `scripts.read` | View your scripts, code, commits, functions, and collections |
| `scripts.write` | Create and edit scripts, make commits, and manage webhooks |
| `functions.deploy` | Deploy scripts' backend (functions and collections) |
| `ai` | Use DoglyTdc AI with the script owner's credits |
| `scripts.publish` | Publish protected versions and roll back to previous versions |
| `users.manage` | View who uses your scripts and ban, deactivate, or reactivate them |

If the scope is missing, the response is `403 MISSING_SCOPE`.

## Format

* Requests and responses in JSON (`Content-Type: application/json`).
* Errors: `{ "code": "…", "message": "…", "errors": { … } }`. `errors` appears when a field is invalid. See the [error list](https://docs.doglytdc.dev/en/scripts/errors.md).
* Dates in ISO 8601 (UTC).
* Accounts always appear as `@username`.

## Limits

| What | Limit |
| - | - |
| Authenticated calls | 300 per minute (per script with a script token, per account otherwise) |
| Public routes (no login) | 120 per minute per address |
| Commits | 30 per minute per person and script |
| Function calls | 120 per minute per person and script |
| AI | 20 messages per minute per person and script |
| MCP | 120 messages per minute per account |

When exceeded, the response is `429 RATE_LIMITED` with `Retry-After: 60`.

## Webhooks

| Item | Value |
| - | - |
| Events | `repo.commit`, `functions.deploy`, `access.granted`, `ping` |
| Headers | `X-DoglyTdc-Signature`, `X-DoglyTdc-Timestamp`, `X-DoglyTdc-Event`, `X-DoglyTdc-Delivery` |
| Body | `{ id, event, script_id, created_at, data }` |
| Signature | `sha256=hex(HMAC_SHA256(chave, timestamp + "." + corpo_bruto))`; reject timestamps older than 5 minutes |
| Attempts | 3 (immediately, after 1 s, and after 3 s); the webhook is disabled after 10 consecutive failures |

Verify the signature (Node.js):

```js theme={null}
import crypto from "node:crypto";

function assinaturaValida(req, corpoBruto, chave) {
  const ts = req.headers["x-doglytdc-timestamp"];
  const sig = req.headers["x-doglytdc-signature"];
  if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false;
  const esperado = "sha256=" + crypto.createHmac("sha256", chave).update(ts + "." + corpoBruto).digest("hex");
  return crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(esperado));
}
```

## Examples

### Read a file

```bash theme={null}
curl -H "Authorization: Bearer dts_…" https://ucsyxzpdbnuyehizezvb.supabase.co/functions/v1/doglytdc-scripts-api/scripts/{script_id}/repo/files/src/script.js?raw=1
```

### Commit with race protection

```bash theme={null}
curl -X POST -H "Authorization: Bearer dts_…" -H "Content-Type: application/json" https://ucsyxzpdbnuyehizezvb.supabase.co/functions/v1/doglytdc-scripts-api/scripts/{script_id}/repo/commits -d '{"expected_head":"<head_sha de GET /repo/branches>","message":"Atualiza script","changes":[{"path":"src/script.js","content":"console.log(1)"}]}'
```

### AI

```bash theme={null}
curl -X POST -H "Authorization: Bearer dts_…" -H "Content-Type: application/json" https://ucsyxzpdbnuyehizezvb.supabase.co/functions/v1/doglytdc-scripts-api/ai/chat -d '{"messages":[{"role":"user","content":"Oi"}]}'
```

## Routes

> [card] [Scripts](https://docs.doglytdc.dev/en/scripts/api-reference/scripts.md)
>
> 6 route(s)

> [card] [Script token](https://docs.doglytdc.dev/en/scripts/api-reference/token.md)
>
> 3 route(s)

> [card] [Repository](https://docs.doglytdc.dev/en/scripts/api-reference/repository.md)
>
> 7 route(s)

> [card] [Backend functions and deployment](https://docs.doglytdc.dev/en/scripts/api-reference/backend.md)
>
> 3 route(s)

> [card] [Collections and documents](https://docs.doglytdc.dev/en/scripts/api-reference/collections.md)
>
> 6 route(s)

> [card] [Webhooks](https://docs.doglytdc.dev/en/scripts/api-reference/webhooks.md)
>
> 6 route(s)

> [card] [AI and logs](https://docs.doglytdc.dev/en/scripts/api-reference/ai-and-logs.md)
>
> 2 route(s)

> [card] [Authorized apps](https://docs.doglytdc.dev/en/scripts/api-reference/authorizations.md)
>
> 2 route(s)

> [card] [Studio](https://docs.doglytdc.dev/en/scripts/api-reference/studio.md)
>
> Versions, users, configuration


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.