Skip to main content
Neurons can be called using either the REST API directly or our official TypeScript SDK. This guide explains both methods and their options.

REST API

Each Neuron has a unique API URL in the format:

Authentication Requirements

Authentication is only required if enforced by the Neuron’s access control settings. A Neuron can be configured with: When authentication is required, provide it using the Authorization header:
If your Neuron has public access enabled, you can skip the authentication step entirely. See the Access Control documentation for detailed configuration options.

Basic Usage

To call a Neuron, send a POST request to its API URL with your input in JSON format:

Complete Examples

Here are complete examples showing how to call Neurons with error handling and authentication:

Query Parameters

The API supports the following query parameters: Example with query parameters:

Authentication

If your Neuron requires authentication, you can provide it using the Authorization header:
See Access Control for more details about authentication methods.

Response Format

A successful response will have this structure:

Error Handling

Errors are returned with appropriate HTTP status codes and a JSON response:
The API uses standard HTTP status codes to indicate the success or failure of requests:
For 429 responses, check the Retry-After header for the number of seconds to wait before retrying:

Error Handling Examples

Here’s how to handle errors in different languages:
For production applications, we recommend implementing proper retry logic with exponential backoff, especially for 429 and 503 errors. See Rate Limiting for more details about handling rate limits.

TypeScript SDK

We provide an official TypeScript SDK for a more convenient integration experience.

Installation

Authentication

The SDK supports both authenticated and unauthenticated calls, depending on your Neuron’s access control settings. Authentication is only required if your Neuron is configured to use API Key or JWT authentication. If authentication is needed, you can provide it in multiple ways:
  1. During client creation:
  1. Using the setter method:
  1. Per request:
If your Neuron has public access enabled, you can omit the authentication token. The SDK will work without authentication for public Neurons.

Basic Usage

Complete Example

Here’s a comprehensive example showing different ways to use the SDK:

Advanced Options

The callNeuron method accepts these options:
Example with options:

Type Safety

The SDK provides TypeScript types for all responses:

Error Handling

The SDK provides built-in error handling with TypeScript types, and exposes the error status code and message from the API. Here’s how to handle different error scenarios:
The SDK throws typed errors that include both the error message and status code, making it easy to implement specific error handling logic for different scenarios.

Complete Example

Here’s a comprehensive example showing different ways to use the SDK: