### Install and Run Cursor2API (Bash) Source: https://context7.com/7836246/cursor2api/llms.txt Provides commands to install dependencies, configure the service, and run it in development or production modes using npm. ```bash # Install dependencies npm install # Copy and customize configuration cp config.yaml.example config.yaml # Development mode (with hot reload) npm run dev # Production mode npm run build && npm start ``` -------------------------------- ### GET / Source: https://context7.com/7836246/cursor2api/llms.txt The root endpoint provides basic service information and lists all available API endpoints. ```APIDOC ## Root Endpoint ### GET / ### Description This is the root endpoint of the API. It returns general information about the service, including its name, version, description, and a list of all available endpoints. ### Method GET ### Endpoint / ### Response #### Success Response (200) - **name** (string) - The name of the service. - **version** (string) - The current version of the service. - **description** (string) - A brief description of the service. - **endpoints** (object) - An object containing key-value pairs of available endpoints. ### Response Example ```json { "name": "cursor2api", "version": "2.7.8", "description": "Cursor Docs AI → Anthropic & OpenAI & Cursor IDE API Proxy", "endpoints": { "anthropic_messages": "POST /v1/messages", "openai_chat": "POST /v1/chat/completions", "openai_responses": "POST /v1/responses", "models": "GET /v1/models", "health": "GET /health", "log_viewer": "GET /logs" } } ``` ``` -------------------------------- ### GET /v1/models Source: https://context7.com/7836246/cursor2api/llms.txt Retrieves a list of all available models compatible with both OpenAI and Anthropic APIs. ```APIDOC ## Model List Endpoint ### GET /v1/models ### Description Lists all available models that can be used with the API, supporting both OpenAI and Anthropic model formats. ### Method GET ### Endpoint /v1/models ### Response #### Success Response (200) - **object** (string) - Type of the response, usually "list". - **data** (array) - An array of model objects. - **id** (string) - The unique identifier for the model. - **object** (string) - The type of the object, usually "model". - **created** (integer) - Timestamp of model creation. - **owned_by** (string) - The organization that owns the model (e.g., "anthropic"). ### Response Example ```json { "object": "list", "data": [ {"id": "anthropic/claude-sonnet-4.6", "object": "model", "created": 1234567890, "owned_by": "anthropic"}, {"id": "claude-sonnet-4-5-20250929", "object": "model", "created": 1234567890, "owned_by": "anthropic"}, {"id": "claude-sonnet-4-20250514", "object": "model", "created": 1234567890, "owned_by": "anthropic"}, {"id": "claude-3-5-sonnet-20241022", "object": "model", "created": 1234567890, "owned_by": "anthropic"} ] } ``` ``` -------------------------------- ### GET /logs Source: https://context7.com/7836246/cursor2api/llms.txt Provides access to a web-based log viewer with real-time SSE streaming, request inspection, and status filtering. ```APIDOC ## Log Viewer and Monitoring ### GET /logs ### Description This endpoint provides a web-based interface for viewing logs. It supports real-time Server-Sent Events (SSE) streaming, allows inspection of individual requests, and filtering by status. ### Method GET ### Endpoint /logs ### Usage Access the web UI by navigating to `http://localhost:3010/logs` in your browser. For authenticated access, append your token: `http://localhost:3010/logs?token=sk-your-secret-token-1` ### API Endpoints for Log Data - **Get recent requests**: `curl http://localhost:3010/api/requests?token=sk-your-secret-token-1` - **Get request payload details**: `curl http://localhost:3010/api/payload/req_abc123?token=sk-your-secret-token-1` - **Get statistics**: `curl http://localhost:3010/api/stats?token=sk-your-secret-token-1` ``` -------------------------------- ### Interact with Anthropic Messages API (Bash) Source: https://context7.com/7836246/cursor2api/llms.txt Demonstrates how to set up environment variables and use curl to interact with the Cursor2API's Anthropic Messages API endpoint for chat completions and token counting. Includes examples for streaming responses. ```bash # Set environment variables for Claude Code export ANTHROPIC_BASE_URL=http://localhost:3010 export ANTHROPIC_API_KEY=sk-your-secret-token-1 # Start Claude Code claude # Or use curl directly for chat completion curl -X POST http://localhost:3010/v1/messages \ -H "Content-Type: application/json" \ -H "Authorization: Bearer sk-your-secret-token-1" \ -d '{ "model": "claude-3-5-sonnet-20241022", "max_tokens": 8192, "stream": true, "messages": [ { "role": "user", "content": "Write a Python function to calculate fibonacci numbers" } ], "tools": [ { "name": "Write", "description": "Write content to a file", "input_schema": { "type": "object", "properties": { "file_path": { "type": "string" }, "content": { "type": "string" } }, "required": ["file_path", "content"] } } ] }' # Expected streaming response (SSE format): # event: message_start # data: {"type":"message_start","message":{"id":"msg_...","type":"message","role":"assistant",...}} # event: content_block_start # data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}} # event: content_block_delta # data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Here's a..."}} # ... # event: message_stop # data: {"type":"message_stop"} # Use curl for token counting curl -X POST http://localhost:3010/v1/messages/count_tokens \ -H "Content-Type: application/json" \ -H "Authorization: Bearer sk-your-secret-token-1" \ -d '{ "model": "claude-3-5-sonnet-20241022", "messages": [ {"role": "user", "content": "Hello, how are you?"} ] }' # Response: # {"input_tokens": 12} ``` -------------------------------- ### GET /api/logs/stream Source: https://context7.com/7836246/cursor2api/llms.txt Establishes a Server-Sent Events (SSE) connection to stream real-time logs from the Cursor2API service. ```APIDOC ## GET /api/logs/stream ### Description Streams real-time logs from the server using Server-Sent Events (SSE). ### Method GET ### Endpoint /api/logs/stream ### Parameters #### Query Parameters - **token** (string) - Required - The secret authentication token for accessing the log stream. ### Request Example curl http://localhost:3010/api/logs/stream?token=sk-your-secret-token-1 ### Response #### Success Response (200) - **text/event-stream** - A continuous stream of log data in JSON format. ``` -------------------------------- ### Interact with OpenAI Chat Completions API (Bash) Source: https://context7.com/7836246/cursor2api/llms.txt Shows how to use curl to send requests to the Cursor2API's OpenAI Chat Completions API endpoint for non-streaming chat interactions. Includes an example request and its expected JSON response. ```bash # Non-streaming request curl -X POST http://localhost:3010/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer sk-your-secret-token-1" \ -d '{ "model": "claude-sonnet-4-20250514", "messages": [ {"role": "system", "content": "You are a helpful coding assistant."}, {"role": "user", "content": "Explain async/await in JavaScript"} ], "temperature": 0.7, "max_tokens": 2048 }' # Response: # { # "id": "chatcmpl-abc123...", # "object": "chat.completion", # "created": 1234567890, # "model": "claude-sonnet-4-20250514", # "choices": [{ # "index": 0, # "message": { # "role": "assistant", # "content": "Async/await is a modern JavaScript feature..." # }, # "finish_reason": "stop" # }], # "usage": {"prompt_tokens": 25, "completion_tokens": 150, "total_tokens": 175} # } ``` -------------------------------- ### GET /health Source: https://context7.com/7836246/cursor2api/llms.txt A health check endpoint used for monitoring and load balancer configurations. ```APIDOC ## Health Check Endpoint ### GET /health ### Description Provides a simple health status of the API service. Useful for monitoring and load balancer health checks. ### Method GET ### Endpoint /health ### Response #### Success Response (200) - **status** (string) - The health status of the service (e.g., "ok"). - **version** (string) - The current version of the service. ### Response Example ```json { "status": "ok", "version": "2.7.8" } ``` ``` -------------------------------- ### Configure Logging and Persistence Source: https://context7.com/7836246/cursor2api/llms.txt Set up persistent logging using either JSONL files or a SQLite database for tracking request history. ```yaml logging: file_enabled: false dir: "./logs" max_days: 7 persist_mode: summary db_enabled: true db_path: "./logs/cursor2api.db" ``` -------------------------------- ### Basic Configuration for Cursor2API (YAML) Source: https://context7.com/7836246/cursor2api/llms.txt Illustrates the basic configuration structure for Cursor2API, including service port, authentication tokens, model selection, timeouts, and history limits. ```yaml # Service port port: 3010 # API authentication tokens (recommended for public deployment) auth_tokens: - "sk-your-secret-token-1" - "sk-your-secret-token-2" # Cursor model to use cursor_model: "anthropic/claude-sonnet-4.6" # Request timeout in seconds timeout: 120 # Optional proxy for external connections # proxy: "http://127.0.0.1:7890" # History token limit (recommended: 120000) max_history_tokens: 120000 # Automatic continuation for truncated responses (0 = disabled) max_auto_continue: 0 ``` -------------------------------- ### Configure Tool Definitions Source: https://context7.com/7836246/cursor2api/llms.txt Manage how tools are passed to the model, including schema modes, whitelisting, and adaptive budget settings. ```yaml tools: schema_mode: 'compact' description_max_length: 100 include_only: - "Read" - "Write" - "Bash" - "Edit" passthrough: false disabled: false adaptive_budget: true smart_truncation: true ``` -------------------------------- ### Retrieve Available Models Source: https://context7.com/7836246/cursor2api/llms.txt Queries the models endpoint to list all AI models compatible with the proxy service. ```bash curl http://localhost:3010/v1/models ``` -------------------------------- ### Retrieve Service Information Source: https://context7.com/7836246/cursor2api/llms.txt Fetches root service metadata including available endpoints and versioning. ```bash curl http://localhost:3010/ ``` -------------------------------- ### POST /v1/chat/completions (Streaming with Tool Calls) Source: https://context7.com/7836246/cursor2api/llms.txt Initiates a chat completion request with streaming enabled and supports tool calls for integrating external functions. ```APIDOC ## POST /v1/chat/completions ### Description This endpoint allows for streaming chat completions and supports tool calls, enabling the model to interact with external functions. ### Method POST ### Endpoint /v1/chat/completions ### Parameters #### Request Body - **model** (string) - Required - The model to use for the chat completion. - **stream** (boolean) - Required - Whether to stream the response. - **messages** (array) - Required - An array of message objects representing the conversation history. - **tools** (array) - Optional - A list of tools the model can use. ### Request Example ```json { "model": "claude-sonnet-4-20250514", "stream": true, "messages": [ {"role": "user", "content": "Create a file called hello.py with a greeting function"} ], "tools": [ { "type": "function", "function": { "name": "write_file", "description": "Write content to a file", "parameters": { "type": "object", "properties": { "path": {"type": "string"}, "content": {"type": "string"} }, "required": ["path", "content"] } } } ] } ``` ### Response #### Success Response (200) - **delta** (object) - For streaming responses, contains partial message content or tool calls. - **tool_calls** (array) - If a tool call is made, this array contains the details. #### Response Example (Streaming Delta) ```json { "type": "content", "content": [ { "type": "tool_use", "id": "toolu_0123456789abcdef", "name": "write_file", "input": { "path": "hello.py", "content": "def greet():\n print('Hello, world!')" } } ] } ``` ``` -------------------------------- ### Configure Thinking Mode and API Requests Source: https://context7.com/7836246/cursor2api/llms.txt Enable chain-of-thought reasoning in configuration and execute API requests for Anthropic or OpenAI models with thinking enabled. ```yaml thinking: enabled: true ``` ```bash # Anthropic API with thinking block curl -X POST http://localhost:3010/v1/messages \ -H "Content-Type: application/json" \ -d '{ "model": "claude-3-5-sonnet-20241022", "max_tokens": 8192, "thinking": {"type": "enabled"}, "messages": [{"role": "user", "content": "Solve this complex problem..."}] }' # OpenAI API with thinking curl -X POST http://localhost:3010/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "claude-thinking", "messages": [{"role": "user", "content": "Solve this complex problem..."}] }' ``` -------------------------------- ### POST /v1/chat/completions Source: https://context7.com/7836246/cursor2api/llms.txt Provides full OpenAI Chat Completions API compatibility for OpenAI-compatible clients. ```APIDOC ## POST /v1/chat/completions ### Description Full OpenAI Chat Completions API compatibility for clients like ChatBox and LobeChat. ### Method POST ### Endpoint /v1/chat/completions ### Parameters #### Request Body - **model** (string) - Required - The model to use. - **messages** (array) - Required - The conversation history. - **temperature** (number) - Optional - Sampling temperature. ### Request Example { "model": "claude-sonnet-4-20250514", "messages": [{"role": "user", "content": "Explain async/await"}] } ### Response #### Success Response (200) - **id** (string) - Chat completion ID. - **choices** (array) - List of completion choices. #### Response Example { "id": "chatcmpl-abc123", "choices": [{"message": {"role": "assistant", "content": "..."}}], "usage": {"prompt_tokens": 25, "completion_tokens": 150} } ``` -------------------------------- ### Deploy with Docker Compose Source: https://context7.com/7836246/cursor2api/llms.txt Deploy the Cursor2API service using Docker Compose, including volume mapping for configuration and logs. ```yaml version: '3.8' services: cursor2api: build: . ports: - "3010:3010" volumes: - ./config.yaml:/app/config.yaml:ro - ./logs:/app/logs environment: - PORT=3010 - AUTH_TOKEN=sk-your-secret-token - MAX_HISTORY_TOKENS=120000 restart: unless-stopped ``` ```bash # Build and start docker-compose up -d # View logs docker-compose logs -f # Rebuild after updates docker-compose build && docker-compose up -d ``` -------------------------------- ### Perform Streaming Chat Completion with Tool Calls Source: https://context7.com/7836246/cursor2api/llms.txt Sends a POST request to the chat completions endpoint with streaming enabled and tool definitions. This allows the model to perform actions like file writing based on user input. ```bash curl -X POST http://localhost:3010/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer sk-your-secret-token-1" \ -d '{ "model": "claude-sonnet-4-20250514", "stream": true, "messages": [ {"role": "user", "content": "Create a file called hello.py with a greeting function"} ], "tools": [{ "type": "function", "function": { "name": "write_file", "description": "Write content to a file", "parameters": { "type": "object", "properties": { "path": {"type": "string"}, "content": {"type": "string"} }, "required": ["path", "content"] } } }] }' ``` -------------------------------- ### POST /v1/responses (Cursor IDE Agent Mode) Source: https://context7.com/7836246/cursor2api/llms.txt Supports the OpenAI Responses API format, compatible with Cursor IDE's Agent mode and Codex. ```APIDOC ## POST /v1/responses ### Description This endpoint supports the OpenAI Responses API format, commonly used by Cursor IDE's Agent mode and Codex for code generation and interaction. ### Method POST ### Endpoint /v1/responses ### Parameters #### Request Body - **model** (string) - Required - The model to use (e.g., "gpt-4"). - **stream** (boolean) - Optional - Whether to stream the response. - **instructions** (string) - Optional - Initial instructions for the agent. - **input** (string) - Required - The user's input or prompt. - **tools** (array) - Optional - A list of tools the model can use. ### Request Example ```json { "model": "gpt-4", "stream": true, "instructions": "You are a helpful coding assistant.", "input": "Write a Python hello world program", "tools": [ { "type": "function", "name": "write_file", "description": "Write content to a file", "parameters": { "type": "object", "properties": { "path": {"type": "string"}, "content": {"type": "string"} } } } ] } ``` ### Response #### Success Response (200) - **response** (object) - Contains details about the response, including status and content. - **delta** (object) - For streaming responses, contains partial output. #### Response Example (Streaming SSE format) ``` event: response.created data: {"type":"response.created","response":{"id":"resp_...","status":"in_progress",...}} event: response.output_text.delta data: {"type":"response.output_text.delta","delta":"Here's..."} event: response.completed data: {"type":"response.completed","response":{"status":"completed",...}} ``` ``` -------------------------------- ### Configure History Compression Source: https://context7.com/7836246/cursor2api/llms.txt Set parameters for intelligent history management to prevent context overflow, including compression levels and token limits. ```yaml compression: enabled: true level: 2 keep_recent: 6 early_msg_max_chars: 2000 max_history_tokens: 120000 context_pressure: 1.35 ``` -------------------------------- ### Stream Real-time Logs via SSE Source: https://context7.com/7836246/cursor2api/llms.txt Access the real-time log stream from the Cursor2API server using a simple curl command with an authentication token. ```bash curl http://localhost:3010/api/logs/stream?token=sk-your-secret-token-1 ``` -------------------------------- ### POST /v1/chat/completions Source: https://context7.com/7836246/cursor2api/llms.txt Endpoint for OpenAI-compatible chat completion requests. ```APIDOC ## POST /v1/chat/completions ### Description Processes chat completion requests compatible with the OpenAI API standard. ### Method POST ### Endpoint /v1/chat/completions ### Request Body - **model** (string) - Required - The model identifier. - **messages** (array) - Required - The conversation history. ### Request Example { "model": "claude-thinking", "messages": [{"role": "user", "content": "Solve this complex problem..."}] } ``` -------------------------------- ### Interact with OpenAI Responses API Source: https://context7.com/7836246/cursor2api/llms.txt Supports the specialized OpenAI Responses API format used by Cursor IDE's Agent mode, providing event-based streaming responses. ```bash curl -X POST http://localhost:3010/v1/responses \ -H "Content-Type: application/json" \ -H "Authorization: Bearer sk-your-secret-token-1" \ -d '{ "model": "gpt-4", "stream": true, "instructions": "You are a helpful coding assistant.", "input": "Write a Python hello world program", "tools": [{ "type": "function", "name": "write_file", "description": "Write content to a file", "parameters": { "type": "object", "properties": { "path": {"type": "string"}, "content": {"type": "string"} } } }] }' ``` -------------------------------- ### POST /v1/chat/completions (JSON Schema Response Format) Source: https://context7.com/7836246/cursor2api/llms.txt Enables requesting chat completions with responses formatted as JSON, optionally validated against a provided JSON schema. ```APIDOC ## POST /v1/chat/completions with response_format ### Description Request JSON-formatted responses with optional schema validation. This is useful for structured data extraction. ### Method POST ### Endpoint /v1/chat/completions ### Parameters #### Request Body - **model** (string) - Required - The model to use. - **messages** (array) - Required - An array of message objects. - **response_format** (object) - Optional - Specifies the desired response format. - **type** (string) - Required - The type of response format, e.g., `json_schema`. - **json_schema** (object) - Required if type is `json_schema`. - **schema** (object) - Required - The JSON schema to validate against. ### Request Example ```json { "model": "claude-sonnet-4-20250514", "messages": [ {"role": "user", "content": "List 3 programming languages with their use cases"} ], "response_format": { "type": "json_schema", "json_schema": { "schema": { "type": "object", "properties": { "languages": { "type": "array", "items": { "type": "object", "properties": { "name": {"type": "string"}, "use_case": {"type": "string"} } } } } } } } } ``` ### Response #### Success Response (200) - **content** (object) - The response will be a JSON object conforming to the provided schema. ``` -------------------------------- ### POST /v1/messages Source: https://context7.com/7836246/cursor2api/llms.txt Endpoint for Anthropic-compatible requests, supporting extended thinking modes and tool calling. ```APIDOC ## POST /v1/messages ### Description Processes messages using the Anthropic API format, including support for thinking blocks. ### Method POST ### Endpoint /v1/messages ### Request Body - **model** (string) - Required - The model identifier. - **max_tokens** (integer) - Optional - Maximum tokens for the response. - **thinking** (object) - Optional - Configuration for enabling chain-of-thought reasoning. - **messages** (array) - Required - The conversation history. ### Request Example { "model": "claude-3-5-sonnet-20241022", "max_tokens": 8192, "thinking": {"type": "enabled"}, "messages": [{"role": "user", "content": "Solve this complex problem..."}] } ``` -------------------------------- ### Configure Vision Processing Source: https://context7.com/7836246/cursor2api/llms.txt Enable and configure image processing fallback modes, supporting either local OCR or external vision model APIs. ```yaml vision: enabled: true mode: 'ocr' base_url: "https://openrouter.ai/api/v1/chat/completions" api_key: "sk-or-v1-..." model: "meta-llama/llama-3.2-11b-vision-instruct:free" proxy: "http://127.0.0.1:7890" ``` -------------------------------- ### Request Structured JSON Responses Source: https://context7.com/7836246/cursor2api/llms.txt Utilizes the response_format parameter to enforce a specific JSON schema on the model output. This is useful for programmatic data extraction. ```bash curl -X POST http://localhost:3010/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer sk-your-secret-token-1" \ -d '{ "model": "claude-sonnet-4-20250514", "messages": [ {"role": "user", "content": "List 3 programming languages with their use cases"} ], "response_format": { "type": "json_schema", "json_schema": { "schema": { "type": "object", "properties": { "languages": { "type": "array", "items": { "type": "object", "properties": { "name": {"type": "string"}, "use_case": {"type": "string"} } } } } } } } }' ``` -------------------------------- ### Check Service Health Source: https://context7.com/7836246/cursor2api/llms.txt Verifies the operational status and version of the proxy service. ```bash curl http://localhost:3010/health ``` -------------------------------- ### Access Log Monitoring API Source: https://context7.com/7836246/cursor2api/llms.txt Retrieves recent request logs, specific payload details, or system statistics for monitoring purposes. ```bash curl http://localhost:3010/api/requests?token=sk-your-secret-token-1 curl http://localhost:3010/api/payload/req_abc123?token=sk-your-secret-token-1 curl http://localhost:3010/api/stats?token=sk-your-secret-token-1 ``` -------------------------------- ### POST /v1/messages Source: https://context7.com/7836246/cursor2api/llms.txt Provides full Anthropic Messages API compatibility, supporting streaming, tool use, and extended thinking. ```APIDOC ## POST /v1/messages ### Description Provides full Anthropic Messages API compatibility for Claude Code and other Anthropic clients. ### Method POST ### Endpoint /v1/messages ### Parameters #### Request Body - **model** (string) - Required - The model to use. - **messages** (array) - Required - The conversation history. - **stream** (boolean) - Optional - Whether to stream the response. - **tools** (array) - Optional - Definitions of tools the model can use. ### Request Example { "model": "claude-3-5-sonnet-20241022", "messages": [{"role": "user", "content": "Write a Python function"}], "stream": true } ### Response #### Success Response (200) - **id** (string) - Unique message identifier. - **content** (array) - The assistant's response content. #### Response Example { "type": "message", "role": "assistant", "content": [{"type": "text", "text": "..."}] } ``` -------------------------------- ### POST /v1/messages/count_tokens Source: https://context7.com/7836246/cursor2api/llms.txt Calculates the token count for a given request payload without executing the API call. ```APIDOC ## POST /v1/messages/count_tokens ### Description Count tokens for a request payload without making an actual API call. ### Method POST ### Endpoint /v1/messages/count_tokens ### Parameters #### Request Body - **model** (string) - Required - The model to use. - **messages** (array) - Required - The messages to count. ### Request Example { "model": "claude-3-5-sonnet-20241022", "messages": [{"role": "user", "content": "Hello"}] } ### Response #### Success Response (200) - **input_tokens** (integer) - Total token count. #### Response Example { "input_tokens": 12 } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.