Skip to content

A Cloudflare Workers-based AI-powered Web Search service that provides information retrieval capabilities using Tavily API.

License

Notifications You must be signed in to change notification settings

pinacai/pinac-ai-search

Repository files navigation

Deploy to Cloudflare

Pinac AI Search Service

A Cloudflare Workers-based AI-powered Web Search service that provides information retrieval capabilities using Tavily API.

Features

  • 🔍 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

Setup

Prerequisites

  • Node.js 18+
  • Cloudflare account with Workers AI enabled
  • Wrangler CLI

Installation

  1. Clone the repository:
git clone <repository-url>
cd pinac-nexus
  1. Install dependencies:
npm install
  1. 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"
  1. Configure Wrangler:
npx wrangler login
  1. Deploy to Cloudflare Workers:
npm run deploy

Development

Run locally with Wrangler:

npm run dev

Usage Example

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 Codes

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

Author

@RajeshTechForge

About

A Cloudflare Workers-based AI-powered Web Search service that provides information retrieval capabilities using Tavily API.

Resources

License

Stars

Watchers

Forks