const express = require('express'); const morgan = require('morgan'); const { createProxyMiddleware } = require('http-proxy-middleware'); const url = require('url'); const app = express(); app.use(morgan('dev')); // Get proxy configuration from environment variables const proxyUrl = process.env.PROXY || ''; console.log(`Proxy configuration: ${proxyUrl ? 'Configured' : 'Not configured'}`); console.log(`Raw proxy URL: ${proxyUrl}`); // Print the raw proxy URL // Parse proxy URL let proxyConfig = null; if (proxyUrl) { try { const parsedUrl = url.parse(proxyUrl); proxyConfig = { host: parsedUrl.hostname, port: parsedUrl.port || 80, auth: parsedUrl.auth ? { username: parsedUrl.auth.split(':')[0], password: parsedUrl.auth.split(':')[1] } : undefined }; // Print EXACT proxy configuration with actual username and password console.log('Using proxy with EXACT credentials:', JSON.stringify(proxyConfig)); if (proxyConfig.auth) { console.log('EXACT AUTH DETAILS:'); console.log('Username:', proxyConfig.auth.username); console.log('Password:', proxyConfig.auth.password); } } catch (error) { console.error('Failed to parse proxy URL:', error.message); } } // Add models list API app.get('/hf/v1/models', (req, res) => { const models = { "object": "list", "data": [ { "id": "claude-3.5-sonnet", "object": "model", "created": 1706745938, "owned_by": "cursor" }, { "id": "gpt-4", "object": "model", "created": 1706745938, "owned_by": "cursor" }, { "id": "gpt-4o", "object": "model", "created": 1706745938, "owned_by": "cursor" }, { "id": "claude-3-opus", "object": "model", "created": 1706745938, "owned_by": "cursor" }, { "id": "gpt-3.5-turbo", "object": "model", "created": 1706745938, "owned_by": "cursor" }, { "id": "gpt-4-turbo-2024-04-09", "object": "model", "created": 1706745938, "owned_by": "cursor" }, { "id": "gpt-4o-128k", "object": "model", "created": 1706745938, "owned_by": "cursor" }, { "id": "gemini-1.5-flash-500k", "object": "model", "created": 1706745938, "owned_by": "cursor" }, { "id": "claude-3-haiku-200k", "object": "model", "created": 1706745938, "owned_by": "cursor" }, { "id": "claude-3-5-sonnet-200k", "object": "model", "created": 1706745938, "owned_by": "cursor" }, { "id": "claude-3-5-sonnet-20241022", "object": "model", "created": 1706745938, "owned_by": "cursor" }, { "id": "gpt-4o-mini", "object": "model", "created": 1706745938, "owned_by": "cursor" }, { "id": "o1-mini", "object": "model", "created": 1706745938, "owned_by": "cursor" }, { "id": "o1-preview", "object": "model", "created": 1706745938, "owned_by": "cursor" }, { "id": "o1", "object": "model", "created": 1706745938, "owned_by": "cursor" }, { "id": "claude-3.5-haiku", "object": "model", "created": 1706745938, "owned_by": "cursor" }, { "id": "gemini-exp-1206", "object": "model", "created": 1706745938, "owned_by": "cursor" }, { "id": "gemini-2.0-flash-thinking-exp", "object": "model", "created": 1706745938, "owned_by": "cursor" }, { "id": "gemini-2.0-flash-exp", "object": "model", "created": 1706745938, "owned_by": "cursor" }, { "id": "deepseek-v3", "object": "model", "created": 1706745938, "owned_by": "cursor" }, { "id": "deepseek-r1", "object": "model", "created": 1706745938, "owned_by": "cursor" }, // New models { "id": "claude-3.7-sonnet", "object": "model", "created": 1706745938, "owned_by": "cursor" }, { "id": "claude-3.7-sonnet-thinking", "object": "model", "created": 1706745938, "owned_by": "cursor" } ] }; res.json(models); }); // Configure proxy middleware app.use('/hf/v1/chat/completions', createProxyMiddleware({ target: 'http://localhost:3010/v1/chat/completions', changeOrigin: true, // Add proxy configuration proxy: proxyConfig, // Add error handling onError: (err, req, res) => { console.error('Proxy error:', err); res.status(500).send('Proxy error occurred: ' + err.message); }, onProxyReq: (proxyReq, req, res) => { console.log(`Proxying request to chat completions ${proxyConfig ? 'using proxy' : 'directly'}`); }, onProxyRes: (proxyRes, req, res) => { console.log(`Received response with status: ${proxyRes.statusCode}`); } })); app.get('/', (req, res) => { const htmlContent = ` Cursor To OpenAI

Cursor To OpenAI Server

Dark Mode
Chat Source: Custom (OpenAI Compatible)
Custom Endpoint (Base URL):
Custom API Key: [Cursor Cookie in format user_...]
Proxy Status: ${proxyConfig ? 'Enabled' : 'Disabled'} ${proxyConfig ? `

Proxy Server: ${proxyConfig.host}:${proxyConfig.port}

` : ''}

Supported Models

Loading...

How to Connect to Cursor API

Step 1: Authentication

To authenticate with the Cursor API, you need to obtain your Cursor cookie:

  1. Log in to Cursor.so
  2. Open browser developer tools (F12)
  3. Go to Application tab → Cookies
  4. Find the cookie that starts with "user_..."
  5. Use this value as your API key in the Authorization header

Step 2: Set up your API client

Configure your API client with the following settings:

  • Base URL:
  • Headers: Authorization: Bearer your_cursor_cookie
  • Content-Type: application/json

Step 3: Make API requests

Example request to generate a completion:

fetch('/chat/completions', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer your_cursor_cookie' }, body: JSON.stringify({ model: 'claude-3.7-sonnet', messages: [ { role: 'user', content: 'Hello, who are you?' } ], temperature: 0.7 }) }) .then(response => response.json()) .then(data => console.log(data));
`; res.send(htmlContent); }); const port = process.env.HF_PORT || 7860; app.listen(port, () => { console.log(`HF Proxy server is running at PORT: ${port}`); console.log(`Proxy status: ${proxyConfig ? 'Enabled' : 'Disabled'}`); });