Provisioning & Initial Setup¶
This guide covers the one-time setup process for all required Cloudflare services.
1. Prerequisites¶
Before you begin, ensure you have the following:
- Node.js: Version 18 or higher.
- Wrangler CLI: The command-line interface for Cloudflare's developer platform.
# Install Wrangler globally
npm install -g wrangler@latest
# Log in to your Cloudflare account
wrangler login
# Verify your identity and note your Account ID
wrangler whoami
- Cloudflare Account: Your account must have Workers, Vectorize, and AI Gateway enabled.
- API Token (for CI/CD): For automated deployments, create a Cloudflare API token with the following permissions:
Account.Workers Scripts: EditAccount.Vectorize: Write
2. Provisioning Checklist¶
Step 1: Create AI Gateway¶
The AI Gateway provides a unified endpoint for interacting with third-party LLMs, adding caching, rate limiting, and observability.
- In the Cloudflare dashboard, navigate to AI → AI Gateway.
- Click Create Gateway.
- Set the Gateway Name to
labeeb-core. - In the gateway's settings, enable Logging and Cache responses.
- Copy the OpenAI-compatible base URL. You will need this for the API configuration.
Step 2: Create Vectorize Indexes¶
Vectorize is Cloudflare's vector database. We need to create an index for each environment (dev, stage, prod).
Run for Each Environment
The following commands create the index and its required metadata fields. Repeat the create-metadata-index commands for labeeb-articles-stage and labeeb-articles.
| Environment | Index Name | wrangler vectorize create ... |
|---|---|---|
| Development | labeeb-articles-dev |
... labeeb-articles-dev --dimensions=1024 --metric=cosine |
| Staging | labeeb-articles-stage |
... labeeb-articles-stage --dimensions=1024 --metric=cosine |
| Production | labeeb-articles |
... labeeb-articles --dimensions=1024 --metric=cosine |
# Create the development index
wrangler vectorize create labeeb-articles-dev --dimensions=1024 --metric=cosine
# Add metadata indexes to the development index
wrangler vectorize create-metadata-index labeeb-articles-dev --property-name=lang --type=string
wrangler vectorize create-metadata-index labeeb-articles-dev --property-name=source --type=string
wrangler vectorize create-metadata-index labeeb-articles-dev --property-name=published_at_bucket --type=number
Step 3: Create Shared Secret¶
Create a secure secret to authenticate requests between the API service and the Cloudflare worker.
-
Generate a strong secret:
-
Set the secret for each worker environment:
-
Add the secret to the API's
.envfile: This key allows the API to securely communicate with the worker.