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

# Cloudflare® Workers Bindings & Environment Variables

> Comprehensive reference for Cloudflare bindings (D1, R2, KV, DO, Queues, Workers AI, Vectorize, Analytics Engine) used across Hoox workers.

This document provides a comprehensive reference for all bindings, environment variables, and secrets used in the Cloudflare® Workers project.

## Table of Contents

* [Secrets & Environment Variables](#secrets--environment-variables)
* [Service Bindings](#service-bindings)
* [KV Namespace Bindings](#kv-namespace-bindings)
* [R2 Bucket Bindings](#r2-bucket-bindings)
* [D1 Database Bindings](#d1-database-bindings)
* [AI Bindings](#ai-bindings)
* [Vectorize Bindings](#vectorize-bindings)
* [Browser Bindings](#browser-bindings)

## Secrets & Environment Variables

| Variable                  | Type   | Workers                             | Description                                                    |
| ------------------------- | ------ | ----------------------------------- | -------------------------------------------------------------- |
| `INTERNAL_KEY_BINDING`    | Secret | telegram-worker, hoox, trade-worker | Internal authentication key for worker-to-worker communication |
| `TG_BOT_TOKEN_BINDING`    | Secret | telegram-worker                     | Telegram Bot API token                                         |
| `TG_CHAT_ID_BINDING`      | Secret | telegram-worker                     | Telegram chat ID for notifications                             |
| `TELEGRAM_SECRET_TOKEN`   | Secret | telegram-worker                     | Webhook verification token for Telegram                        |
| `AUTHORIZED_CHAT_IDS`     | Secret | telegram-worker                     | Comma-separated chat IDs authorized to send bot commands       |
| `WEBHOOK_API_KEY_BINDING` | Secret | hoox                                | API key for webhook endpoints                                  |
| `WALLET_PK_SECRET`        | Secret | web3-wallet-worker                  | Private key for Web3 wallet operations                         |
| `WALLET_MNEMONIC_SECRET`  | Secret | web3-wallet-worker                  | Mnemonic phrase for wallet generation                          |
| `MEXC_KEY_BINDING`        | Secret | trade-worker                        | MEXC exchange API key                                          |
| `MEXC_SECRET_BINDING`     | Secret | trade-worker                        | MEXC exchange API secret                                       |
| `BINANCE_KEY_BINDING`     | Secret | trade-worker                        | Binance exchange API key                                       |
| `BINANCE_SECRET_BINDING`  | Secret | trade-worker                        | Binance exchange API secret                                    |
| `BYBIT_KEY_BINDING`       | Secret | trade-worker                        | Bybit exchange API key                                         |
| `BYBIT_SECRET_BINDING`    | Secret | trade-worker                        | Bybit exchange API secret                                      |
| `CLOUDFLARE_API_TOKEN`    | Secret | analytics-worker                    | CF API token for Analytics SQL queries                         |

## Service Bindings

| Binding            | Worker                                                              | Connected Service | Description                     |
| ------------------ | ------------------------------------------------------------------- | ----------------- | ------------------------------- |
| `TRADE_SERVICE`    | hoox, agent-worker, email-worker                                    | trade-worker      | Access to trading functionality |
| `TELEGRAM_SERVICE` | hoox, trade-worker, agent-worker, web3-wallet-worker, report-worker | telegram-worker   | Telegram notifications          |
| `D1_SERVICE`       | trade-worker, agent-worker, report-worker, dashboard                | d1-worker         | Centralized D1 database service |
| `AGENT_SERVICE`    | dashboard                                                           | agent-worker      | Agent worker access             |

## KV Namespace Bindings

| Binding       | Worker                                                                                | Description                        |
| ------------- | ------------------------------------------------------------------------------------- | ---------------------------------- |
| `CONFIG_KV`   | hoox, trade-worker, agent-worker, telegram-worker, d1-worker, email-worker, dashboard | Configuration + rate limiter state |
| `SESSIONS_KV` | hoox                                                                                  | Webhook session storage            |

## R2 Bucket Bindings

| Binding          | Worker          | Bucket Name   | Description                    |
| ---------------- | --------------- | ------------- | ------------------------------ |
| `UPLOADS_BUCKET` | telegram-worker | user-uploads  | Store user uploaded files      |
| `REPORTS_BUCKET` | trade-worker    | trade-reports | Store trading reports and data |

## D1 Database Bindings

| Binding | Worker       | Database Name | Description                    |
| ------- | ------------ | ------------- | ------------------------------ |
| `DB`    | d1-worker    | trade-data-db | Main database for trading data |
| `DB`    | trade-worker | trade-data-db | Database for trade operations  |
| `DB`    | agent-worker | trade-data-db | Portfolio queries              |

## AI Bindings

| Binding | Worker                                         | Description                                   |
| ------- | ---------------------------------------------- | --------------------------------------------- |
| `AI`    | hoox, agent-worker, telegram-worker, dashboard | Access to Cloudflare® Workers AI capabilities |

## Vectorize Bindings

| Binding           | Worker                | Index Name   | Description                          |
| ----------------- | --------------------- | ------------ | ------------------------------------ |
| `VECTORIZE_INDEX` | hoox, telegram-worker | my-rag-index | Vector database for RAG applications |

## Analytics Engine Bindings

| Binding            | Worker           | Dataset        | Description                          |
| ------------------ | ---------------- | -------------- | ------------------------------------ |
| `ANALYTICS_ENGINE` | analytics-worker | hoox-analytics | Time-series metrics from all workers |

## Browser Rendering

Report-worker uses the Cloudflare Browser Rendering **REST API** (no wrangler binding needed):

```
POST https://api.cloudflare.com/client/v4/accounts/{id}/browser-rendering/pdf
Authorization: Bearer {CF_API_TOKEN}
Body: { html: "...", options: { format: "A4" } }
```

## Local Development URLs

For local development with `wrangler dev`, the following service URLs are used:

| Service            | Local URL                                      | Used By                                               |
| ------------------ | ---------------------------------------------- | ----------------------------------------------------- |
| hoox (Gateway)     | [http://localhost:8787](http://localhost:8787) | Webhook clients                                       |
| Trade Worker       | [http://localhost:8789](http://localhost:8789) | hoox, agent-worker, email-worker                      |
| Telegram Worker    | [http://localhost:8791](http://localhost:8791) | hoox, trade-worker, agent-worker, web3-wallet, report |
| d1-worker          | [http://localhost:8792](http://localhost:8792) | trade-worker, agent-worker, report, dashboard         |
| Web3 Wallet Worker | [http://localhost:8793](http://localhost:8793) | trade-worker                                          |
| dashboard          | [http://localhost:8794](http://localhost:8794) | Users (browser)                                       |
| agent-worker       | [http://localhost:8795](http://localhost:8795) | dashboard                                             |
| email-worker       | [http://localhost:8796](http://localhost:8796) | — (cron triggered)                                    |
| report-worker      | [http://localhost:8797](http://localhost:8797) | — (cron triggered)                                    |

## Configuration

Each worker contains a `.dev.vars` file for local development which should be populated with the appropriate values. These files should not be committed to the repository.

Example setup for `.dev.vars` files can be found in the corresponding `.dev.vars.example` files in each worker directory.

## Setting Up Secrets

For production deployment, secrets should be set using the Wrangler CLI:

```bash theme={null}
wrangler secret put SECRET_NAME
```

This will securely store the secret and make it available to the worker at runtime.

***

*Cloudflare® and the Cloudflare logo are trademarks and/or registered trademarks of Cloudflare, Inc. in the United States and other jurisdictions.*
