> ## 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.

# fetch, AI and secrets

> Call authorized sites, use DoglyTdc AI and read secrets in functions.

## doglytdc.fetch

Calls an external site. It only works for **authorized domains** in the script's Backend tab.

```js theme={null}
function handler(request) {
  const r = doglytdc.fetch("https://api.exemplo.com/dados", {
    method: "GET",
    headers: { Accept: "application/json" },
  });
  if (!r.ok) return doglytdc.respond(502, { erro: r.status });
  return doglytdc.respond(200, JSON.parse(r.text));
}
```

| Option | Rule |
| - | - |
| `method` | `GET`, `POST`, `PUT`, `PATCH`, `DELETE` or `HEAD` |
| `headers` | Up to 20 headers |
| `body` | Text up to 256 KB |

Response: `{ status, ok, headers: { "content-type" }, text }`.

Security rules:

* `https` only.
* Public addresses only: IPs and domains pointing to a private network are blocked.
* Domain must be on the Backend tab list. `*.exemplo.com` covers `exemplo.com` and all its subdomains.
* Redirects are not followed.
* Up to 10 calls per run, 4 seconds each, responses up to 1 MB.

![Screenshot: AI keys for your scripts](https://mintcdn.com/dogly-tdc/qOnot79kPtISSKbW/images/scripts/scripts-api-keys.png?fit=max\&auto=format\&n=qOnot79kPtISSKbW\&q=85\&s=afac227a4847002ab962d8dab3057032)

AI keys for your scripts

## doglytdc.ai.chat

Uses DoglyTdc AI (GPT-6 Luna model). Credits come from the **script owner's** account.

```js theme={null}
function handler(request) {
  const r = doglytdc.ai.chat([
    { role: "system", content: "Responda em uma frase." },
    { role: "user", content: String((request.body || {}).pergunta || "") },
  ]);
  return doglytdc.respond(200, { resposta: r.text });
}
```

| Rule | Value |
| - | - |
| Messages | From 1 to 30, with `role` `system`, `user` or `assistant` |
| Size of each message | Up to 20,000 characters |
| Calls per run | 3 |
| Response | `{ text, model }` |

DoglyTdc reserves the credits first and settles by actual usage afterwards. Errors: "Sem créditos de IA na conta do dono do script." (no AI credits in the owner's account), "IA ocupada: tente de novo em instantes." (AI busy, try again shortly), "A IA demorou demais para esta função (limite de 5 s)." (AI took too long, 5 s limit).

## Secrets

Store API keys in the Backend tab as secrets. In the function, read them with `doglytdc.env.NAME`. Secrets are stored encrypted and never appear in the API or to the AI.


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