Chat Completions
Chat API
Chat Completions
Stream AI-powered responses with full codebase context
POST
Chat Completions
Overview
The Chat Completions endpoint enables AI-powered conversations with deep understanding of your codebase. It streams responses in real-time, providing contextually aware answers based on your indexed repositories and workspaces.Request
Array of message objects representing the conversation history.
Array of data source objects to use as context. Each object must have an
id field with the data source ID.Example: [{"id": "69087243381f39ef605c3841"}]Required: You must specify either dataSources OR names (at least one is required).Alternative to
dataSources - array of data source names (strings) to use as context.Example: ["MyWorkspace", "my-repository"]Required: You must specify either dataSources OR names (at least one is required).Whether to stream the response as Server-Sent Events (SSE).
Optional conversation ID to continue an existing conversation.
Enable debug mode for additional information in the response.
Response
Streaming Response
Whenstream: true, the endpoint returns Server-Sent Events (SSE). The response includes:
- Metadata event (sent first) - Contains conversation and message IDs:
- Content chunks - The actual response content:
- Done event (sent last) - Indicates stream completion:
Always
"message" for SSE eventsEvent type in metadata:
"metadata" (first event only)Unique identifier for the conversation. Use this ID to continue the conversation in subsequent requests by passing it in the
conversationId field.Unique identifier for the assistant’s message in this conversation
Text content chunk (for content events)
Content type:
"content" for text chunks, "done" for completionSet to
true in the final event to indicate stream completionNon-Streaming Response
Whenstream: false, returns a complete response:
Specifying Data Sources
You have two options for specifying which repositories/workspaces to search:- By ID - Use
dataSourceswith an array of objects containing data source IDs - By Name - Use
nameswith an array of data source name strings
Code Examples
Data Source Selection Examples
Use Cases
Multi-Turn Conversations
Use theconversationId from the metadata event to maintain conversation context across multiple requests:
Code Explanation
Bug Analysis
Architecture Review
Code Generation
Error Responses
400 Bad Request
404 Not Found
429 Rate Limited
Best Practices
Optimize Context
Optimize Context
- Specify relevant datasources to improve response quality
- Include conversation history for better context
- Use system messages to set behavior expectations
Handle Streaming
Handle Streaming
- Implement proper error handling for SSE connections
- Buffer responses for better user experience
- Handle connection timeouts gracefully
Token Management
Token Management
- Monitor token usage in responses
- Set appropriate max_tokens limits
- Consider response chunking for large outputs