A Cloudflare Workers-based AI-powered Web Search service that provides information retrieval capabilities using Tavily API.
- 🔍 AI-powered Web Search service
- 📡 Server-sent events (SSE) streaming responses
- 🛡️ Robust error handling with structured JSON responses
- ⚡ Built on Cloudflare Workers for global edge deployment
- 🔒 Input validation and content-type enforcement
- Node.js 18+
- Cloudflare account with Workers AI enabled
- Wrangler CLI
- Clone the repository:
git clone <repository-url>
cd pinac-nexus
- Install dependencies:
npm install
- Configure Environment Variables:
Add your Tavily API key as credentials to your wrangler.toml
or Cloudflare dashboard:
[vars]
TAVILY_API_KEY = "your_tavily_api_key"
- Configure Wrangler:
npx wrangler login
- Deploy to Cloudflare Workers:
npm run deploy
Run locally with Wrangler:
npm run dev
Note
It will be accessed through API-Getway and need user ID-Token for authentication
// Using fetch API
const response = await fetch(
"https://api-getway-url/api/search",
{
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_USER_ID_TOKEN",
},
body: JSON.stringify({
prompt: "What about mumbai ?",
messages: [
{
role: "user",
content: "What is the current weather in Delhi?",
},
{
role: "assistant",
content: "The current weather in Delhi is sunny and warm.",
}
],
}),
}
);
Error Code | Description | Status Code |
---|---|---|
METHOD_NOT_ALLOWED |
Only POST requests are allowed | 405 |
INVALID_CONTENT_TYPE |
Request missing required JSON content-type | 415 |
BAD_REQUEST |
Request body must include 'prompt' and 'messages' fields | 400 |
AI_SEARCH_SERVER_ERROR |
Server processing error | 500 |
@RajeshTechForge