Skip to Content
DocumentationAPI Documentation

API Documentation

NeuraScale provides comprehensive APIs for integrating with brain-computer interface devices, managing neural data, and building applications. Our API ecosystem includes REST, GraphQL, WebSocket, and gRPC interfaces to support various integration patterns.

API Overview

REST API v2

✓ Available

Standard HTTP operations for device management and data access

Documentation →

GraphQL API

🚀 Coming Soon

Flexible queries with real-time subscriptions

Documentation →

WebSocket API

🔧 Beta

Real-time bidirectional communication for streaming data

Documentation →

gRPC API

📅 Planned

High-performance streaming for real-time applications

Documentation →

Quick Start

Authentication

All API requests require authentication using JWT tokens:

# Get access token curl -X POST https://api.neurascale.io/v2/auth/login \ -H "Content-Type: application/json" \ -d '{"email": "your-email@example.com", "password": "your-password"}' # Use token in requests curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \ https://api.neurascale.io/v2/devices

Base URLs

EnvironmentBase URLStatus
Productionhttps://api.neurascale.io🚀 Coming Soon
Staginghttps://staging-api.neurascale.io🚀 Coming Soon
Developmenthttp://localhost:8000✓ Available

Rate Limits

API TypeRate LimitNotes
REST API1,000 requests/hourPer user token
GraphQL500 queries/hourComplexity-weighted
WebSocket10 connectionsPer user
gRPCUnlimitedProduction use only

REST API v2 ✓ Available

Our REST API follows OpenAPI 3.0 specification and provides standard HTTP operations for all platform resources.

The REST API is currently available for local development. Production deployment coming soon with full authentication and rate limiting.

Device Management Endpoints

# List all devices GET /v2/devices # Get device details GET /v2/devices/{device_id} # Start device streaming POST /v2/devices/{device_id}/stream/start # Stop device streaming POST /v2/devices/{device_id}/stream/stop # Update device configuration PATCH /v2/devices/{device_id}/config

Example: Connect OpenBCI Device

const response = await fetch('https://api.neurascale.io/v2/devices/openbci_001/stream/start', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_TOKEN', 'Content-Type': 'application/json' }, body: JSON.stringify({ sample_rate: 250, channels: [1, 2, 3, 4, 5, 6, 7, 8], filters: { notch: 60, highpass: 0.5, lowpass: 100 } }) }); const result = await response.json(); console.log('Stream started:', result.stream_id);

GraphQL API 🚀 Coming Soon

Our GraphQL API provides a unified interface for querying related data efficiently with strong typing and real-time subscriptions.

GraphQL API is under active development and will be available in the next release. The schema and examples below show the planned implementation.

GraphQL Endpoint

POST https://api.neurascale.io/graphql

Schema Overview

Common Queries

# Get devices with recent sessions query GetDevicesWithSessions { devices { id name status sessions(last: 5) { id name startTime status recordings { id duration sampleCount quality } } } } # Query specific session data query GetSessionData($sessionId: ID!) { session(id: $sessionId) { id name startTime endTime device { id name type } recordings { id channelCount sampleRate duration artifacts { type startTime endTime } } analysis { id modelType accuracy predictions { timestamp label confidence } } } } # Search sessions with filters query SearchSessions($filters: SessionFilters) { sessions(filters: $filters) { edges { node { id name startTime tags metadata } } pageInfo { hasNextPage hasPreviousPage startCursor endCursor } } }

WebSocket API 🔧 Beta

For real-time bidirectional communication, our WebSocket API provides low-latency streaming of neural data and events.

WebSocket API is currently in beta with core functionality available. Full production features including compression and advanced event filtering coming soon.

Connection

const ws = new WebSocket('wss://api.neurascale.io/ws'); // Authentication ws.onopen = () => { ws.send(JSON.stringify({ type: 'auth', token: 'YOUR_ACCESS_TOKEN' })); }; // Handle messages ws.onmessage = (event) => { const message = JSON.parse(event.data); console.log('Received:', message); };

Message Types

Neural Data Streaming

// Subscribe to data stream ws.send(JSON.stringify({ type: 'subscribe', topic: 'neural_data', session_id: 'session_123' })); // Real-time data message format { "type": "neural_data", "timestamp": 1705317045123, "device_id": "openbci_001", "session_id": "session_123", "channels": [ { "number": 1, "value": 1.23, "quality": 0.98 }, { "number": 2, "value": 4.56, "quality": 0.99 }, { "number": 3, "value": 7.89, "quality": 0.97 } ], "events": [ { "type": "stimulus", "timestamp": 1705317045120, "data": { "stimulus_id": "stim_001" } } ] } // Batch data for efficiency { "type": "neural_data_batch", "batch_id": "batch_123", "timestamp_start": 1705317045000, "timestamp_end": 1705317049000, "sample_count": 1000, "compressed_data": "base64_encoded_data" }

gRPC API 📅 Planned

For high-performance applications requiring low latency and efficient binary protocol, our gRPC API provides streaming interfaces.

gRPC API is planned for future release to support high-frequency neural data streaming. The protocol buffers and examples below show the planned implementation.

Protocol Buffers

// neural_service.proto syntax = "proto3"; package neurascale.v1; service NeuralService { // Streaming neural data rpc StreamNeuralData(StreamRequest) returns (stream NeuralDataPacket); // Bidirectional device control rpc DeviceControl(stream DeviceCommand) returns (stream DeviceResponse); // Analysis service rpc AnalyzeData(AnalysisRequest) returns (AnalysisResponse); } message NeuralDataPacket { string device_id = 1; int64 timestamp = 2; repeated ChannelData channels = 3; repeated Event events = 4; } message ChannelData { int32 channel_number = 1; float value = 2; float quality = 3; } message Event { string type = 1; int64 timestamp = 2; map<string, string> metadata = 3; }

Client Examples

Python gRPC Client

import grpc from neurascale.v1 import neural_service_pb2_grpc, neural_service_pb2 # Create channel with authentication credentials = grpc.ssl_channel_credentials() call_credentials = grpc.access_token_call_credentials('YOUR_TOKEN') composite_credentials = grpc.composite_channel_credentials( credentials, call_credentials ) channel = grpc.secure_channel( 'api.neurascale.io:443', composite_credentials ) # Create service stub stub = neural_service_pb2_grpc.NeuralServiceStub(channel) # Stream neural data request = neural_service_pb2.StreamRequest( session_id='session_123', device_ids=['openbci_001'] ) try: for packet in stub.StreamNeuralData(request): print(f"Received data from {packet.device_id}") for channel in packet.channels: print(f" Channel {channel.channel_number}: {channel.value}") except grpc.RpcError as e: print(f"Error: {e.code()} - {e.details()}")

Error Handling

HTTP Status Codes

CodeDescriptionCommon Causes
200SuccessRequest completed successfully
201CreatedResource created successfully
400Bad RequestInvalid request format or parameters
401UnauthorizedMissing or invalid authentication
403ForbiddenInsufficient permissions
404Not FoundResource does not exist
409ConflictResource conflict (e.g., device already in use)
422Unprocessable EntityValid request but business logic error
429Too Many RequestsRate limit exceeded
500Internal Server ErrorServer-side error
503Service UnavailableService temporarily unavailable

Error Response Format

{ "error": { "code": "DEVICE_NOT_FOUND", "message": "Device with ID 'openbci_001' not found", "details": { "resource_type": "device", "resource_id": "openbci_001", "available_devices": ["openbci_002", "emotiv_001"] }, "request_id": "req_123456789", "timestamp": "2024-01-15T10:30:45.123Z" } }

Common Error Codes

CodeDescriptionResolution
INVALID_TOKENJWT token is invalid or expiredRefresh token or re-authenticate
DEVICE_NOT_FOUNDSpecified device doesn’t existCheck device ID and availability
DEVICE_BUSYDevice is already in useWait or use different device
SESSION_NOT_FOUNDSession doesn’t existVerify session ID
INSUFFICIENT_PERMISSIONSUser lacks required permissionsContact administrator
RATE_LIMIT_EXCEEDEDToo many requestsImplement backoff and retry
STREAM_UNAVAILABLEData stream is not activeStart streaming first
INVALID_CONFIGURATIONDevice configuration is invalidCheck configuration parameters

For detailed API documentation including all endpoints, parameters, and examples, visit our interactive API documentation at docs.neurascale.io/api .

Last updated on