# DalalAI Spreadsheet Connectors

Bring DalalAI's analytics straight into your spreadsheets — no copy‑paste, no
manual exports. Both connectors call the **DalalAI Developer API** and send your
key as an `X-API-Key` HTTP header (so it never sits in a URL or a cell).

> Get an API key: **[dalalai.com](https://dalalai.com) ▸ Developer API ▸ Generate Key**.
> Free tier includes 1,000 calls/month and CSV export.

---

## Google Sheets — `=DALALAI()` formula

File: [`dalalai-sheets.gs`](dalalai-sheets.gs)

1. In your sheet: **Extensions ▸ Apps Script**.
2. Paste the whole `dalalai-sheets.gs` file, **Save**, reload the sheet.
3. **DalalAI ▸ Set API key** and paste your key.
4. Use it in any cell:

   ```
   =DALALAI("convergence")                    full convergence table
   =DALALAI("convergence-scores","RELIANCE")  one symbol
   =DALALAI("predictions", , "Symbol,Score")  chosen columns only
   =DALALAI("convergence", , , 25)            cap to 25 rows
   ```

The result spills into a range (header + rows) and recalculates with the sheet.
Force a pull with **DalalAI ▸ Refresh now**.

---

## Excel — Power Query (M)

File: [`dalalai-excel.pq`](dalalai-excel.pq)

1. **Data ▸ Get Data ▸ From Other Sources ▸ Blank Query**.
2. **Home ▸ Advanced Editor**, paste the `dalalai-excel.pq` query, **Done**.
3. Set `ApiKey` and `Endpoint` at the top; when prompted, connect as **Anonymous**.
4. **Close & Load** → a refreshable table. Right‑click ▸ **Refresh** for fresh data.

---

## Endpoints

Any `/api/v1/{endpoint}` documented at **[dalalai.com/api-docs](https://dalalai.com/api-docs)** works, e.g.
`convergence`, `convergence-scores`, `predictions`, `smart-money`, `regime`,
`sectors`, `valuation`.

Supported query params: `symbol`, `fields` (comma‑separated columns),
`limit`, and `format=csv` (added automatically by both connectors).

## Notes & limits

| Tier | Calls/month | Rate |
|------|-------------|------|
| Free | 1,000 | 10 req/s |
| Starter | 50,000 | 50 req/s |
| Pro | 500,000 | 200 req/s |
| Enterprise | Unlimited | Custom |

- A `429` means you've hit the rate limit or monthly quota.
- A `401/403` means the key is wrong or revoked — re‑set it.
- Keep refresh intervals sensible; each refresh counts as one API call per query.
