How libaxuan/cursor2api-go works
Cursor2API is a Go HTTP service that adapts Cursor Web to an OpenAI-compatible chat API. The main workflow is client request → authenticated chat handler → Cursor request/protocol preparation → Cursor Web → parsed assistant events → API response; model listing, health checks, documentation, streaming, thinking variants, and tool calls are additional product capabilities. The excerpts establish routing, configuration, authentication, and portions of the protocol and JavaScript runtime; some internal calls and response paths are documented or implied but not visible, so those links are marked unverified.
Main entry points: cursor.go Cursor Service · handler.go API Handlers · main.go HTTP Server · models.go API Models
Components 21
HTTP API
- HTTP Server
main.go - API Key Auth
middleware/auth.go - API Handlers
handlers/handler.go - Error Middleware
middleware/error.go - CORS Middleware
middleware/cors.go - Health Check
handlers/handler.go - Docs Endpoint
handlers/handler.go
Cursor Adapter
- Cursor Service
services/cursor.go - Request Builder
services/cursor_protocol.go - Event Parser
utils/cursor_protocol.go - Browser Headers
utils/headers.go - Shared Utilities
utils/utils.go
Browser Runtime
- JS Harness
jscode/main.js - Browser Environment
jscode/env.js
Models and Config
- Service Config
config/config.go - API Models
models/models.go - Model Capabilities
models/model_capabilities.go - Model Mapping
models/model_config.go
Other components
- API Client
- Cursor Web
- Node.js Runtime
Connections 29
- API Client → HTTP Server: sends requests
README.md - HTTP Server → Service Config: loads config
main.go - HTTP Server → API Handlers: registers routes
main.go - HTTP Server → API Key Auth: protects chat route
main.go - HTTP Server → CORS Middleware: installs middleware
main.go - HTTP Server → Error Middleware: installs middleware
main.go - API Handlers → Service Config: reads models
handlers/handler.go - API Handlers → Cursor Service: creates service
handlers/handler.go - API Handlers → API Models: binds chat request
handlers/handler.go - API Handlers → Cursor Service: submits chat
- API Handlers → Health Check: serves health
handlers/handler.go - API Handlers → Docs Endpoint: serves docs
handlers/handler.go - Service Config → Model Capabilities: expands model list
config/config.go - API Handlers → Model Capabilities: lists model variants
- Cursor Service → Request Builder: builds Cursor request
- Cursor Service → Browser Headers: sets upstream headers
- Cursor Service → JS Harness: loads JS harness
services/cursor.go - Cursor Service → Browser Environment: loads browser environment
services/cursor.go - JS Harness → Browser Environment: uses environment shim
- Cursor Service → Node.js Runtime: executes JavaScript
- Node.js Runtime → JS Harness: runs harness
- Cursor Service → Cursor Web: calls upstream
services/cursor.go - Request Builder → API Models: builds payload
services/cursor_protocol.go - Request Builder → Shared Utilities: generates request ID
services/cursor_protocol.go - Cursor Service → Event Parser: parses response events
- Event Parser → API Models: emits assistant events
utils/cursor_protocol.go - Cursor Service → API Models: collects chat results
services/cursor.go - Cursor Service → API Client: returns completions
- Model Mapping → Cursor Service: maps model upstream