Skip to Content
API ReferenceSynapSDK

Synap SDK Client

The main entry point for interacting with Synap Data Pod.

Constructor

new SynapSDK(config: SynapSDKConfig)

Configuration

interface SynapSDKConfig { /** Base URL for the Synap API */ url: string /** API key for authentication */ apiKey?: string /** Custom headers function for dynamic auth */ headers?: () => Record<string, string> | Promise<Record<string, string>> /** Custom fetch implementation */ fetch?: typeof globalThis.fetch }

Examples

Basic Setup

import { SynapSDK } from '@synap/sdk' const synap = new SynapSDK({ url: 'https://api.synap.app', apiKey: 'sk_...' })

With Environment Variable

const synap = new SynapSDK({ url: process.env.SYNAP_URL!, apiKey: process.env.SYNAP_API_KEY! })

Dynamic Headers

const synap = new SynapSDK({ url: 'https://api.synap.app', headers: async () => ({ Authorization: `Bearer ${await getToken()}` }) })

Custom Fetch (React Native)

import { SynapSDK } from '@synap/sdk' const synap = new SynapSDK({ url: 'https://api.synap.app', apiKey: 'sk_...', fetch: fetch // React Native's fetch })

Properties

entities

Access to Entities API for managing entities.

synap.entities: EntitiesAPI

See Entities API →

relations

Access to Relations API for managing relationships.

synap.relations: RelationsAPI

See Relations API →

events

Access to Events API for event history.

synap.events: EventsAPI

See Events API →

client

Direct access to underlying tRPC client for advanced usage.

synap.client: TRPCClient

Type Safety

The SDK is fully typed with TypeScript:

import { SynapSDK, EntityType } from '@synap/sdk' const synap = new SynapSDK({...}) // TypeScript knows all available methods const entity = await synap.entities.create({ type: 'task', // Autocomplete for entity types title: 'My Task', metadata: { ... } // Type-checked based on entity type })

Error Handling

All SDK methods can throw errors. Wrap calls in try-catch:

try { const { entityId } = await synap.entities.create({...}) } catch (error) { if (error.code === 'UNAUTHORIZED') { // Handle auth error } console.error('Failed to create entity:', error) }

Next Steps

Last updated on