Skip to main content

Overview

The /api/interview-copilot endpoint provides comprehensive assistance for technical coding interviews. It analyzes coding problems (optionally from screenshots) and returns structured solutions with problem analysis, clean code implementations, walkthroughs, test cases, and personalized mistake tracking based on user history.
This endpoint returns a structured JSON object (not plain text) via SSE streaming.

Endpoint

POST /api/interview-copilot

Authentication

Requires authentication via cookies or Authorization header.
Returns 401 Unauthorized if authentication fails.

Request Body

messages
UIMessage[]
required
Array of conversation messages. The user message typically contains the coding problem description or question.
interface UIMessage {
  id: string
  role: 'user' | 'assistant' | 'system'
  content: string
  parts?: any[]
}
conversationId
string
Optional conversation ID for persisting interview session history. If provided and the session doesn’t exist, a new one will be created with type "interview".
screenshot
string
Optional base64-encoded screenshot of the coding problem. When provided, the AI will analyze the visual content along with the text message.
Useful for capturing LeetCode, HackerRank, or other coding platform problems directly from the screen.

Response

Returns a Server-Sent Events (SSE) stream containing a structured analysis object:
idea
string
Problem analysis in GitHub-flavored Markdown format, including:
  • Key observations about the problem
  • Pattern recognition (e.g., “This is a sliding window problem”)
  • Approach and strategy
  • Time/Space complexity targets
  • Edge cases to consider
code
string
Clean, well-commented implementation code wrapped in triple backticks with language identifier.
def twoSum(nums: List[int], target: int) -> List[int]:
    # HashMap to store value -> index mapping
    seen = {}
    
    for i, num in enumerate(nums):
        complement = target - num
        if complement in seen:
            return [seen[complement], i]
        seen[num] = i
    
    return []
walkthrough
string
Step-by-step explanation in Markdown with:
  • Detailed walkthrough of the solution
  • Complexity analysis table
  • Visual examples if applicable
testCases
array
Array of test case objects with edge cases and validation inputs.
Array<{
  input: string,    // Test input
  output: string,   // Expected output
  reason: string    // Why this test case matters
}>
mistakes
array
Personalized array of common mistakes based on the user’s history. Retrieved from user’s stored memories.
Array<{
  mistake: string,     // What the user commonly does wrong
  correction: string,  // The correct approach
  pattern: string      // Category of mistake
}>
memories
array
All relevant memories retrieved about the user during analysis.
Array<{
  memory: string,      // Memory content
  createdAt: string    // ISO timestamp
}>

Available Tools

The endpoint uses memory tools to personalize the analysis:

Example Request

const response = await fetch('/api/interview-copilot', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    messages: [
      {
        id: '1',
        role: 'user',
        content: 'Given an array of integers nums and an integer target, return indices of the two numbers that add up to target.'
      }
    ],
    conversationId: 'interview_session_123'
  })
});

// Parse SSE stream
const reader = response.body.getReader();
const decoder = new TextDecoder();

while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  
  const chunk = decoder.decode(value);
  const lines = chunk.split('\n');
  
  for (const line of lines) {
    if (line.startsWith('data: ')) {
      const data = JSON.parse(line.slice(6));
      
      if (data.type === 'text') {
        // Parse the structured analysis object
        const analysis = JSON.parse(data.content);
        console.log(analysis.idea);      // Problem analysis
        console.log(analysis.code);      // Solution code
        console.log(analysis.testCases); // Test cases
        console.log(analysis.mistakes);  // Personalized mistakes
      }
    }
  }
}

Example with Screenshot

// Capture screenshot and convert to base64
const screenshot = await captureScreen(); // Your screenshot function
const base64Image = btoa(screenshot);

const response = await fetch('/api/interview-copilot', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    messages: [
      {
        id: '1',
        role: 'user',
        content: 'Analyze this LeetCode problem'
      }
    ],
    screenshot: base64Image,
    conversationId: 'interview_session_123'
  })
});

Error Responses

400 Bad Request
error
Returned when messages parameter is missing or invalid.
"Missing messages"
401 Unauthorized
error
Returned when authentication fails.
"Unauthorized"

Features

  • Visual Analysis: Process screenshots of coding problems from any platform
  • Structured Output: Consistent JSON schema for easy parsing and display
  • Personalized Mistakes: Tracks and surfaces common errors from user history
  • Memory Integration: Remembers preferred languages, coding styles, and past struggles
  • Beautiful Formatting: All text fields use GitHub-flavored Markdown
  • Conversation Persistence: Saves full interview sessions with metadata
  • Automatic Stopping: Limits to 5 reasoning steps to ensure fast responses

Use Cases

  • Live Interview Assistance: Get real-time help during technical interviews
  • LeetCode Practice: Analyze and solve practice problems with personalized guidance
  • Learning from Mistakes: Track patterns in errors and improve over time
  • Interview Preparation: Study solutions with detailed explanations and complexity analysis
  • Code Review: Understand optimal approaches and edge cases for common problems

Best Practices

  • Include screenshots when possible for more accurate problem analysis
  • Use conversationId to maintain interview session history
  • The system learns from your coding patterns - more usage means better personalization
  • Review the mistakes field to avoid repeating common errors
  • Check memories to see what the system knows about your preferences

Build docs developers (and LLMs) love