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.
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).
{ "content": "The authentication flow starts in the AuthService class...", "conversationId": "507f1f77bcf86cd799439011", "messageId": "507f191e810c19729de860ea"}
Use the conversationId from the metadata event to maintain conversation context across multiple requests:
Copy
import requestsurl = "https://app.codealive.ai/api/chat/completions"headers = {"Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json"}# First message - creates a new conversationresponse1 = requests.post(url, headers=headers, json={ "messages": [{"role": "user", "content": "What is the authentication flow?"}], "stream": False})result1 = response1.json()conversation_id = result1['conversationId']# Follow-up message - continues the conversationresponse2 = requests.post(url, headers=headers, json={ "messages": [{"role": "user", "content": "How is the JWT token validated?"}], "conversationId": conversation_id, # Use the same conversation ID "stream": False})# The AI will have context from the previous message