Skip to content

xuweizhengo/cursor-free-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

164 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Cursor2API

TypeScript License Node

⚠️ As of 2026-04-01, Cursor Docs page only provides gemini-3-flash. This project may have limited functionality.

A proxy service that converts Cursor Web Docs free AI API into Anthropic Messages API and OpenAI Chat Completions API, enabling use with Claude Code and Cursor IDE.

πŸ“– δΈ­ζ–‡ζ–‡ζ‘£: README_CN.md

How It Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Claude Code  │────▢│              │────▢│              β”‚
β”‚ (Anthropic)  β”‚     β”‚  cursor2api  β”‚     β”‚  Cursor API  β”‚
β”‚              │◀────│  (proxy)      │◀────│  /api/chat   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β–²                    β–²
       β”‚                    β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”
β”‚  Cursor IDE  β”‚     β”‚ OpenAI Compatβ”‚
β”‚(/v1/responsesβ”‚     β”‚(/v1/chat/   β”‚
β”‚ + Agent mode)β”‚     β”‚ completions)β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Core Features

  • Anthropic Messages API β€” Full /v1/messages streaming/non-streaming compatibility for Claude Code
  • OpenAI Chat Completions API β€” /v1/chat/completions for ChatBox, LobeChat and other clients
  • Cursor IDE Agent Mode β€” /v1/responses endpoint with flat tool format and incremental streaming
  • Full-link Log Viewer β€” Web UI for real-time request/response/tool call inspection with dark/light theme
  • API Token Auth β€” Bearer token / x-api-key dual mode with multi-token support
  • Thinking Support β€” Client-driven Anthropic thinking block + OpenAI reasoning_content
  • response_format Support β€” json_object / json_schema with auto markdown stripping
  • Tool Parameter Auto-fix β€” Field name mapping, smart quote replacement, fuzzy matching
  • Vision Fallback β€” Built-in CPU OCR for image text extraction (zero config), or external vision API
  • Full Tool Support β€” No tool whitelist, all MCP tools and custom extensions supported
  • Multi-layer Refusal Defense β€” 50+ regex patterns (CN/EN), auto-retry + cognitive reframing bypass
  • Identity Protection β€” Probe interception + refusal retry + response sanitization
  • Truncation Continuation β€” Seamless resume of truncated long Write/Edit calls
  • Progressive History Compression β€” Smart message type recognition, tool call summarization
  • Schema Compression β€” Compacts full JSON Schema (~135k chars) to compact type signatures (~15k chars)
  • Chrome TLS Fingerprint β€” Simulates real browser request headers
  • SSE Streaming β€” Real-time response with 128-byte incremental tool call chunks

Quick Start

1. Install

git clone https://github.com/xuweizhengo/cursor-free-api.git
cd cursor-free-api
npm install

2. Configure

cp config.yaml.example config.yaml

Key options:

Option Description Default
port Server port 3010
auth_tokens API auth tokens (recommended for public deployment) Allow all
cursor_model Model to use google/gemini-3-flash
max_history_tokens History token limit 120000
vision.enabled Enable vision interception true
vision.mode Vision mode: ocr / api ocr
compression.enabled History compression true
compression.level Compression level 1-3 2
proxy Global proxy (optional) none

3. Run

# Development
npm run dev

# Production
npm run build && npm start

4. Use with Claude Code

export ANTHROPIC_BASE_URL=http://localhost:3010
claude

With auth:

export ANTHROPIC_BASE_URL=http://localhost:3010
export ANTHROPIC_API_KEY=sk-your-secret-token-1
claude

5. Use with Cursor IDE

Set in Cursor IDE settings:

OPENAI_BASE_URL=https://your-domain.example.com/v1

Select a Claude model name (check /v1/models for available models).

⚠️ Cursor Pro subscription may be required for custom Base URL.

Log Viewer

Visit http://localhost:3010/logs after starting the service.

Features:

  • Real-time SSE log streaming
  • Request list with user question as title
  • Global search + time filtering
  • Status filtering (success/degraded/failed/processing/blocked)
  • Detail panel for full request/response inspection
  • Degradation reason display
  • Phase timing visualization
  • Dark/light theme toggle
  • SQLite persistence (recommended) or JSONL file logging

Project Structure

cursor2api/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.ts            # Entry + Express server + routes + auth middleware
β”‚   β”œβ”€β”€ config.ts           # Configuration management
β”‚   β”œβ”€β”€ types.ts            # Type definitions
β”‚   β”œβ”€β”€ constants.ts        # Global constants
β”‚   β”œβ”€β”€ cursor-client.ts    # Cursor API client + Chrome TLS fingerprint
β”‚   β”œβ”€β”€ converter.ts        # Protocol conversion + prompt injection + context cleaning
β”‚   β”œβ”€β”€ handler.ts          # Anthropic API handler + identity protection + refusal defense
β”‚   β”œβ”€β”€ openai-handler.ts   # OpenAI / Cursor IDE compatible handler
β”‚   β”œβ”€β”€ log-viewer.ts       # Full-link log Web UI
β”‚   β”œβ”€β”€ logger.ts           # Log collection + SSE push
β”‚   β”œβ”€β”€ proxy-agent.ts      # Proxy support (global + Vision independent)
β”‚   └── tool-fixer.ts       # Tool parameter auto-fix
β”œβ”€β”€ public/                 # Log viewer static files
β”œβ”€β”€ test/                   # Test suites
β”œβ”€β”€ config.yaml.example     # Config template
β”œβ”€β”€ package.json
└── tsconfig.json

Environment Variables

All config options can be overridden via environment variables (higher priority than config.yaml). See config.yaml.example for details.

Technical Architecture

Cognitive Reframing Strategy

The core insight: instead of fighting Cursor's locked-down "Documentation Assistant" identity, we embrace it. The model is told it's writing API documentation examples, tricking it into outputting tool call JSON blocks that the proxy layer then converts into real tool calls.

Multi-layer Refusal Defense

Layer Location Strategy
L1: Context Cleaning converter.ts Remove refusal text from conversation history
L2: XML Separation converter.ts Separate Claude Code system reminders from user requests
L3: Output Interception handler.ts 50+ regex patterns to intercept refusals in real-time
L4: Response Sanitization handler.ts Post-process all output to replace Cursor identity references

Disclaimer

This project is for educational and research purposes only. It is not affiliated with Cursor or Anysphere. Users should comply with Cursor's Terms of Service and assume all risks. The author is not responsible for any account bans or consequences.

Related Projects

License

MIT

About

Convert Cursor free API to OpenAI/Anthropic compatible format

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors