Skip to content

Commit 07333a1

Browse files
authored
Merge pull request #1121 from Portkey-AI/feat/cleanup-handlerutils
refactored tryPost
2 parents 16d9f39 + b6ad9fb commit 07333a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+6238
-647
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,4 @@ build
142142
plugins/**/.creds.json
143143
plugins/**/creds.json
144144
plugins/**/.parameters.json
145+
src/handlers/tests/.creds.json

CLAUDE.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is the **Portkey AI Gateway** - a fast, reliable AI gateway that routes requests to 250+ LLMs with sub-1ms latency. It's built with Hono framework for TypeScript/JavaScript and can be deployed to multiple environments including Cloudflare Workers, Node.js servers, and Docker containers.
8+
9+
## Development Commands
10+
11+
### Core Development
12+
- `npm run dev` - Start development server using Wrangler (Cloudflare Workers)
13+
- `npm run dev:node` - Start development server using Node.js
14+
- `npm run build` - Build the project for production
15+
- `npm run build-plugins` - Build the plugin system
16+
17+
### Testing
18+
- `npm run test:gateway` - Run tests for the main gateway code (src/)
19+
- `npm run test:plugins` - Run tests for plugins
20+
- `jest src/` - Run specific gateway tests
21+
- `jest plugins/` - Run specific plugin tests
22+
23+
### Code Quality
24+
- `npm run format` - Format code with Prettier
25+
- `npm run format:check` - Check code formatting
26+
- `npm run pretty` - Alternative format command
27+
28+
### Deployment
29+
- `npm run deploy` - Deploy to Cloudflare Workers
30+
- `npm run start:node` - Start production Node.js server
31+
32+
## Architecture
33+
34+
### Core Components
35+
36+
**Main Application (`src/index.ts`)**
37+
- Hono-based HTTP server with middleware pipeline
38+
- Handles multiple AI provider integrations
39+
- Routes: `/v1/chat/completions`, `/v1/completions`, `/v1/embeddings`, etc.
40+
41+
**Provider System (`src/providers/`)**
42+
- Modular provider implementations (OpenAI, Anthropic, Azure, etc.)
43+
- Each provider has standardized interface: `api.ts`, `chatComplete.ts`, `embed.ts`
44+
- Provider configs define supported features and transformations
45+
46+
**Middleware Pipeline**
47+
- `requestValidator` - Validates incoming requests
48+
- `hooks` - Pre/post request hooks
49+
- `memoryCache` - Response caching
50+
- `logger` - Request/response logging
51+
- `portkey` - Core Portkey-specific middleware for routing, guardrails, etc.
52+
53+
**Plugin System (`plugins/`)**
54+
- Guardrail plugins for content filtering, PII detection, etc.
55+
- Each plugin has `manifest.json` defining capabilities
56+
- Plugins are built separately with `npm run build-plugins`
57+
58+
### Key Concepts
59+
60+
**Configs** - JSON configurations that define:
61+
- Provider routing and fallbacks
62+
- Load balancing strategies
63+
- Guardrails and content filtering
64+
- Caching and retry policies
65+
66+
**Handlers** - Route-specific request processors in `src/handlers/`
67+
- Each AI API endpoint has dedicated handler
68+
- Stream handling for real-time responses
69+
- WebSocket support for realtime APIs
70+
71+
## File Structure
72+
73+
- `src/providers/` - AI provider integrations
74+
- `src/handlers/` - API endpoint handlers
75+
- `src/middlewares/` - Request/response middleware
76+
- `plugins/` - Guardrail and validation plugins
77+
- `cookbook/` - Example integrations and use cases
78+
- `conf.json` - Runtime configuration
79+
80+
## Testing Strategy
81+
82+
Tests are organized by component:
83+
- `src/tests/` - Core gateway functionality tests
84+
- `src/handlers/__tests__/` - Handler-specific tests
85+
- `plugins/*/**.test.ts` - Plugin tests
86+
- Test timeout: 30 seconds (configured in jest.config.js)
87+
88+
## Configuration
89+
90+
The gateway uses `conf.json` for runtime configuration. Sample config available in `conf_sample.json`.
91+
92+
Key environment variables and configuration handled through Hono's adapter system for multi-environment deployment.

0 commit comments

Comments
 (0)