The Nira API lets you interact with NimbleBrain’s AI assistant programmatically. Create conversations, send messages, and stream responses in real-time to build custom chat interfaces.
Non-streaming requests block until Nira finishes responding. For long responses, this can take 30+ seconds. Use streaming for a better user experience.
Stream the response in real-time for a typewriter effect:
Copy
for await (const event of nb.nira.messages.stream(conversationId, 'Tell me a story')) { switch (event.type) { case 'message.start': console.log('Nira started responding...'); break; case 'content': // Display text as it arrives process.stdout.write(event.data.text as string); break; case 'tool.start': console.log(`\n[Using tool: ${event.data.display}]`); break; case 'tool.complete': console.log('[Tool finished]'); break; case 'done': console.log('\n--- Response complete ---'); break; case 'error': console.error('Error:', event.data.error); break; }}
See Streaming for more details on building streaming chat interfaces.
Nira has access to all connections installed in your workspace. When you ask Nira to do something that requires a tool, she’ll use it automatically:
Copy
const conversation = await nb.nira.conversations.create('Weather Check');for await (const event of nb.nira.messages.stream( conversation.id, 'What is the weather in San Francisco?')) { switch (event.type) { case 'tool.start': console.log(`[Nira is checking ${event.data.display}...]`); break; case 'content': process.stdout.write(event.data.text as string); break; }}
Example output:
Copy
[Nira is checking weather...]The current weather in San Francisco is 65°F with partly cloudy skies.The forecast shows a high of 68°F today with no chance of rain.
You can ask Nira to create playbooks programmatically:
Copy
const conversation = await nb.nira.conversations.create('Build Automation');const response = await nb.nira.messages.send( conversation.id, 'Create a playbook that checks our GitHub repo for new issues every hour and posts a summary to #dev-alerts on Slack');console.log(response.content);// Nira will confirm the playbook creation and provide details
Nira maintains context within a conversation. Follow-up messages can reference previous context:
Copy
const conversation = await nb.nira.conversations.create('Project Planning');// First messageawait nb.nira.messages.send(conversation.id, 'I need to set up daily sales reports from Salesforce to Slack');// Follow-up - Nira remembers the contextawait nb.nira.messages.send(conversation.id, 'Actually, make it weekly instead of daily');// Another follow-upawait nb.nira.messages.send(conversation.id, 'And add a summary of support tickets from Zendesk too');