BNCA API Documentation

Dashboard

Getting Started

BNCA provides a simple, fast API for web scraping with intelligent fallback. Get started in minutes with just two endpoints.

Quick Start

1. Get your API key

Sign up and create an API key in your dashboard.

2. Use the API directly or with our client

You can use the API directly via HTTP or use our lightweight client.

3. Start scraping

// Using direct API call
const response = await fetch('https://bnca-api.fly.dev/scrapeurl', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x-api-key': 'your-api-key'
  },
  body: JSON.stringify({ url: 'https://example.com' })
});

const result = await response.json();
console.log('Success:', result.success);
console.log('Content:', result.data);

// Or using our client helper
import { createBNCAClient } from '@/lib/bnca-client';

const client = createBNCAClient('your-api-key');
const result = await client.scrape('https://example.com');
console.log('Content:', result.data);

Authentication

All API requests require authentication using your API key as a Bearer token.

curl -X POST https://bnca-api.fly.dev/scrapeurl \
  -H "x-api-key: your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com"}'

API Endpoints

The BNCA API provides intelligent web scraping with automatic fallback between Direct Fetch → Lightpanda → Puppeteer.

POST /scrapeurl

Main endpoint for scraping web content with intelligent fallback

Request Body

{
  "url": "https://example.com",     // Required: URL to scrape
  "screenshot": false,             // Optional: Include screenshot
  "question": "What is this about?" // Optional: AI question to answer
}

POST /quickshot

Fast screenshot-only endpoint

Usage

// Using fetch
const response = await fetch('https://bnca-api.fly.dev/quickshot', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x-api-key': 'your-api-key'
  },
  body: JSON.stringify({ url: 'https://example.com' })
});

const result = await response.json();
console.log('Screenshot:', result.screenshot); // Base64 image

Response Format

{
  "success": true,
  "data": {
    "title": "Page Title",
    "content": "Main content...",
    "description": "Meta description",
    "headings": [...],
    "links": [...],
    "structuredData": {...}
  },
  "metadata": {
    "method": "lightpanda",        // Method that succeeded
    "timestamp": "2024-01-01T...",
    "responseTime": 1234
  },
  "screenshot": "data:image/png;base64,..." // If requested
}

GET /health

Check API health status

Usage

const screenshot = await scraper.screenshot('https://example.com', {
  width: 1920,
  height: 1080,
  fullPage: true,
  quality: 90,
  format: 'png'    // 'png' or 'jpeg'
});

if (screenshot.success) {
  console.log('Screenshot saved to:', screenshot.path);
  console.log('Size:', screenshot.size, 'bytes');
}

scraper.askAI(url, question)

Ask AI questions about webpage content

Usage

const result = await scraper.askAI(
  'https://example.com', 
  'What is this website about?'
);

if (result.success) {
  console.log('Answer:', result.answer);
  console.log('Scrape method used:', result.method);
  console.log('Processing time:', result.scrapeTime, 'ms');
}

With API Key (Recommended)

// Use backend API for better AI responses
const scraper = new BNCASmartScraper({
  apiKey: 'your-api-key',
  apiUrl: 'https://bnca-api.fly.dev'
});

const result = await scraper.askAI(
  'https://news.site.com',
  'What are the top 3 headlines?'
);

Utility Methods

Additional methods for monitoring and cleanup

Health Check

// Check if all components are working
const health = await scraper.healthCheck();
console.log('Lightpanda available:', health.lightpanda);
console.log('Puppeteer available:', health.puppeteer);

Cleanup Resources

// Clean up browser instances and resources
await scraper.cleanup();

Get Statistics

// Get performance statistics
const stats = scraper.getStats();
console.log('Success rates:', stats);

Standalone Functions

Convenience functions for quick operations

Quick Scrape

import { smartScrape } from '@monostate/node-scraper';

// One-off scraping without class instantiation
const result = await smartScrape('https://example.com', {
  timeout: 5000,
  verbose: true
});

Quick Screenshot

import { smartScreenshot, quickShot } from '@monostate/node-scraper';

// High-quality screenshot
const screenshot = await smartScreenshot('https://example.com');

// Fast screenshot for previews
const preview = await quickShot('https://example.com', {
  width: 800,
  height: 600
});

AI Analysis

import { askWebsiteAI } from '@monostate/node-scraper';

// Ask AI about a webpage
const result = await askWebsiteAI(
  'https://example.com',
  'What services does this company offer?',
  { apiKey: 'your-api-key' }
);

console.log('Answer:', result.answer);

API Endpoints

POST /scrapeurl

Extract data from any website with intelligent fallback system

Request Body

{
  "url": "https://example.com",    // Required: URL to scrape
  "screenshot": false              // Optional: Take screenshot (default: false)
}

Response

{
  "success": true,
  "data": {
    "title": "Example Domain",
    "content": "This domain is for use in illustrative examples...",
    "metaDescription": "Example description",
    "links": [
      {
        "text": "More information...",
        "href": "https://www.iana.org/domains/example"
      }
    ],
    "images": [
      {
        "src": "https://example.com/image.jpg",
        "alt": "Example image"
      }
    ],
    "structuredData": { /* JSON-LD data if found */ }
  },
  "metadata": {
    "url": "https://example.com",
    "method": "direct",              // direct | lightpanda | puppeteer
    "timestamp": "2024-01-01T00:00:00.000Z",
    "performance": {
      "totalTime": 1234
    },
    "screenshot": null              // Base64 image if requested
  }
}

JavaScript Example

const response = await fetch('https://api.bnca.monostate.ai/scrapeurl', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer your_api_key',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    url: 'https://news.ycombinator.com',
    screenshot: true
  })
});

const result = await response.json();
console.log('Page title:', result.data.title);
console.log('Extraction method:', result.metadata.method);

POST /aireply

Get AI-powered answers about webpage content

Request Body

{
  "url": "https://example.com",           // Required: URL to analyze
  "question": "What is this page about?", // Required: Question to ask
  "screenshot": false                     // Optional: Take screenshot
}

Response

{
  "success": true,
  "answer": "This page is about domain examples used in documentation...",
  "metadata": {
    "url": "https://example.com",
    "question": "What is this page about?",
    "method": "direct",
    "timestamp": "2024-01-01T00:00:00.000Z",
    "performance": {
      "totalTime": 2345,
      "scrapeTime": 1234,
      "processingTime": 1111
    },
    "screenshot": null
  }
}

JavaScript Example

const response = await fetch('https://api.bnca.monostate.ai/aireply', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer your_api_key',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    url: 'https://techcrunch.com/2024/01/01/some-article',
    question: 'What are the main points of this article?'
  })
});

const result = await response.json();
console.log('AI Answer:', result.answer);

Screenshots

Both endpoints support optional screenshot capture using Puppeteer.

Screenshot Options

Enable Screenshots

{
  "url": "https://example.com",
  "screenshot": true  // Enables screenshot capture
}

Screenshot Response

Screenshots are returned as base64-encoded PNG images in the metadata.

{
  "success": true,
  "data": { /* ... page data ... */ },
  "metadata": {
    "screenshot": "iVBORw0KGgoAAAANSUhEUgAAA..."  // Base64 PNG
  }
}

Display Screenshot

// Convert base64 to image
const imageUrl = `data:image/png;base64,${result.metadata.screenshot}`;

// Display in HTML
document.getElementById('screenshot').src = imageUrl;

// Or save to file (Node.js)
const fs = require('fs');
const buffer = Buffer.from(result.metadata.screenshot, 'base64');
fs.writeFileSync('screenshot.png', buffer);

Error Handling

Error Response Format

{
  "error": "Error type",
  "message": "Human readable error message"
}

Common Status Codes

400Bad Request - Missing required parameters
401Unauthorized - Invalid/missing API key
403Forbidden - Subscription required
429Too Many Requests - Rate limit exceeded
500Internal Server Error

Rate Limits & Pricing

Starter

Free forever

$0
  • • 1,000 requests/month
  • • Standard rate limits
  • • Email support

Standard

Most popular

$29/mo
  • • 10,000 requests/month
  • • Higher rate limits
  • • Priority support
  • • Screenshots included

Scale

For high volume

$99/mo
  • • 100,000 requests/month
  • • Highest rate limits
  • • Priority support
  • • Custom integrations

Support

Get Help

Need assistance? We're here to help.

Status & Performance

Current API performance and status.

⚡ Average response: 3,137ms
✅ 99.9% uptime
🚀 2.85x faster than alternatives