A powerful and efficient API service for managing and optimizing AI prompts, built with Cloudflare Workers.
English | 简体中文
- 🚀 High Performance: Powered by Cloudflare Workers for global edge deployment
- 🔒 Secure Authentication: Bearer token-based authentication system
- 📝 Comprehensive API: Full CRUD operations for prompt management
- 🔍 Smart Optimization: AI-powered prompt optimization capabilities
- 🌐 Global Access: Low-latency access from anywhere in the world
- Runtime: Cloudflare Workers
- Framework: Hono.js
- Language: TypeScript
- Testing: Jest
- Database: Cloudflare D1 (SQLite)
- Development: Wrangler CLI
- Node.js (v18 or later)
- npm or yarn
- Wrangler CLI (for Cloudflare Workers development)
- Cloudflare Account with Workers and D1 database access
- Clone the repository:
git clone <repository-url>
cd smart_prompt_api
- Install dependencies:
npm install
- Copy configuration files:
cp wrangler.example.toml wrangler.toml
-
Update
wrangler.toml
with your Cloudflare account details and D1 database configuration. -
Initialize the database with schema:
wrangler d1 execute DB --local --file=./schema.sql
- Start development server:
npm run dev
The project uses Cloudflare D1 (SQLite) with the following schema:
CREATE TABLE prompts (
id TEXT PRIMARY KEY,
tags TEXT,
creator TEXT NOT NULL,
create_time TEXT NOT NULL,
update_time TEXT NOT NULL,
status INTEGER DEFAULT 1,
is_public INTEGER DEFAULT 0,
source_prompt TEXT NOT NULL,
optimized_prompt TEXT,
token TEXT
);
Detailed API documentation can be found in API Documentation. Key endpoints include:
GET /api/prompts
- List prompts with filtering and sortingPOST /api/prompts
- Create or update a promptDELETE /api/prompts/:id
- Delete a promptPATCH /api/prompts/:id/visibility
- Update prompt visibility
All API endpoints require Bearer token authentication:
Authorization: Bearer <your_token>
npm test
npm run dev
The development server will start at http://localhost:8787
Configure the following in your wrangler.toml
:
DB
- D1 database binding- Other environment-specific variables
- Ensure your Cloudflare account is configured:
wrangler login
- Deploy the application:
npm run deploy
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details