Bike4Mind Logo

Bike4Mind

LoginSee Pricing

B4M API Cookbook

Learn the Bike4Mind API with hands-on examples. Start with “Hello World” and build up to real applications.

🚀 Hello World Demo

Follow these steps to create your first B4M chat session:

1

Enter your API Key

2

Create a Notebook

3

Chat with AI

📝 Code Examples

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();

🎯 Next Steps

📚 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