Learn the Bike4Mind API with hands-on examples. Start with โHello Worldโ and build up to real applications.
Follow these steps to create your first B4M chat session:
Enter your API Key
Create a Notebook
Chat with AI
Copy and adapt these examples for your own applications:
// B4M Hello World - JavaScript/Node.js
const API_KEY = 'your_api_key_here';
const BASE_URL = 'https://app.bike4mind.com/api';
// Step 1: Create a notebook
async function createNotebook() {
const response = await fetch(`${BASE_URL}/sessions/create`, {
method: 'POST',
headers: {
'X-API-Key': API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'Hello World Notebook'
})
});
const notebook = await response.json();
return notebook._id;
}
// Step 2: Send a chat message
async function sendMessage(sessionId, message) {
const response = await fetch(`${BASE_URL}/ai/llm`, {
method: 'POST',
headers: {
'X-API-Key': API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
sessionId: sessionId,
message: message,
historyCount: 10,
fabFileIds: [],
messageFileIds: [],
params: {
model: "gpt-4o-mini",
temperature: 0.7,
max_tokens: 500,
stream: false
},
promptMeta: {
session: {
id: sessionId,
userId: "api-user"
}
}
})
});
const result = await response.json();
return result.content;
}
// Complete example
async function helloWorld() {
try {
// Create a new notebook
const sessionId = await createNotebook();
console.log('Created notebook:', sessionId);
// Send a message
const response = await sendMessage(sessionId, 'Hello! Can you help me get started with Bike4Mind?');
console.log('AI Response:', response);
} catch (error) {
console.error('Error:', error);
}
}
// Run the example
helloWorld();๐ Explore the API
Use the B4M API Explorer to test all available endpoints
๐ File Management
Upload files to your notebooks and reference them in conversations
๐จ Image Generation
Use the AI image endpoints to generate and edit images
๐ Authentication
Implement proper auth flows for production applications