Cursor AI Programming Assistant Configuration Tutorial

Configure Cursor with custom LLM API, unlock programming capabilities of powerful Large Language Models like GPT-4o, Claude 3.5, DeepSeek

Quick Configuration Steps

1

Open Cursor Settings

Access settings page through menu or shortcuts

  • Mac: Cmd + , or Cursor → Preferences
  • Windows: Ctrl + , or File → Preferences
  • Or click the settings icon in the bottom left corner
2

Configure API Key

Add API key in Models tab

  • Select Models tab
  • Click "Add API Key"
  • Enter your API key
  • Select corresponding provider
3

Set API Endpoint

Configure custom API address

  • In Advanced settings
  • Find "API Base URL"
  • Enter custom API address
  • Save settings and restart Cursor
4

Select Default Model

Set commonly used AI model

  • Select from model list
  • Set as default model
  • ConfigureModelParameter
  • Test if connection is normal

ConfigureExample

Basic Configuration

Configure Cursor with custom API

{
  "models": [
    {
      "model": "gpt-4o",
      "contextLength": 128000,
      "title": "GPT-4o",
      "provider": "openai"
    },
    {
      "model": "claude-3-5-sonnet-20241022",
      "contextLength": 200000,
      "title": "Claude 3.5 Sonnet",
      "provider": "anthropic"
    }
  ],
  "apiKeys": {
    "openai": "YOUR_API_KEY",
    "anthropic": "YOUR_API_KEY"
  },
  "apiBaseUrl": {
    "openai": "https://api.example.com/v1",
    "anthropic": "https://api.example.com/v1"
  }
}

Core Feature Usage

Smart Code Completion

Context-based intelligent code suggestions

  • Use Tab to accept suggestions
  • Esc to cancel current suggestion
  • Cmd/Ctrl + → to accept partial suggestion

AI Chat Assistant

Natural language conversation with AI

  • Cmd/Ctrl + L for quick questions
  • Select code then ask for targeted suggestions
  • @filename to reference specific files

Code Refactoring

Smart refactoring and code optimization

  • Select code using Cmd/Ctrl + K
  • Describe refactoring requirements
  • Preview changes then apply

Error Fixing

Automatic detection and fixing of code errors

  • Hover mouse over errors
  • Click lightbulb icon to view fix suggestions
  • One-click apply AI fix solutions

API Key Security Tips

  • • Don't commit API keys to code repositories
  • • Use environment variables or key management tools to store keys
  • • Regularly rotate API keys
  • • Use different keys for different projects
  • • Monitor API usage to prevent abnormal consumption

FAQ Solutions

API Connection Failed

  • Check if API key is correct
  • Verify API endpoint address
  • Confirm network connection is normal
  • Check Cursor log files

Poor Code Suggestion Quality

  • Provide more context information
  • Optimize prompt descriptions
  • Switch to more powerful models
  • Adjust temperature parameters

Slow Response Speed

  • Use faster models (like GPT-3.5)
  • Reduce context length
  • Check network latency
  • Consider using local models

Token Limit Error

  • Reduce selected code amount
  • Process long files in batches
  • Use models supporting longer context
  • Clear unnecessary conversation history

Model Selection Recommendations

Code Generation and Completion

  • GPT-4o: Most powerful general programming capabilities
  • Claude 3.5 Sonnet: Excellent code understanding and generation
  • DeepSeek Coder: Specially optimized programming model

Fast Response Scenarios

  • GPT-4o-mini: Fast and low cost
  • GPT-3.5-turbo: Classic fast model
  • Claude 3.5 Haiku: Lightweight Claude model