Back to AI Docs
Quick Start
Get the AI Service running and make your first API call in under 5 minutes.
1
Configure Environment
Use internal API routing in your environment variables:
# .env.local FEATURE_REMOTE_AI_DISPATCH="false" # Optional: external remote-dispatch override (disabled by default) NEXT_PUBLIC_AI_SERVICE_URL=""
2
Use the Chat Hook
Import and use the useAIChat hook in your component:
'use client'
import { useAIChat } from '@/hooks/use-ai-chat'
export function ChatComponent({ projectId }: { projectId: string }) {
const {
messages,
isStreaming,
sendMessage,
stopStream,
} = useAIChat({
projectId, // Enables knowledge-aware responses
provider: 'openai',
model: 'gpt-5',
})
const handleSubmit = (input: string) => {
sendMessage(input)
}
return (
<div>
{messages.map((msg) => (
<div key={msg.id}>
<strong>{msg.role}:</strong> {msg.content}
{msg.isStreaming && <span className="animate-pulse">▊</span>}
</div>
))}
<form onSubmit={(e) => {
e.preventDefault()
handleSubmit(e.currentTarget.input.value)
}}>
<input name="input" disabled={isStreaming} />
<button type="submit">Send</button>
</form>
</div>
)
}3
Generate Knowledge Base
Index your project to enable context-aware responses:
import { useAITask } from '@/hooks/use-ai-task'
function KnowledgeButton({ projectId }: { projectId: string }) {
const { generateKnowledgeBase, task, isPolling } = useAITask({
onComplete: (status) => {
console.log('Indexed!', status.result)
},
})
return (
<button
onClick={() => generateKnowledgeBase(projectId)}
disabled={isPolling}
>
{isPolling ? 'Indexing...' : 'Generate Knowledge Base'}
</button>
)
}4
Direct API Access (Optional)
For non-React environments, use the AI client directly:
import { getAIClient } from '@/lib/ai/client'
const client = getAIClient()
// Non-streaming chat
const response = await client.chat({
messages: [{ role: 'user', content: 'How is auth implemented?' }],
projectId: 'my-project',
})
// Streaming chat
for await (const chunk of client.streamChat({
messages: [{ role: 'user', content: 'Explain the architecture' }],
projectId: 'my-project',
})) {
process.stdout.write(chunk.content || '')
}