FIDUCY

Server SDK

import { createFiducy, keyValueStorage, memoryStorage } from '@fiducy/sdk/server';

createFiducy(options)

const fiducy = createFiducy({
  gatewayURL: 'https://gw.fiducy.dev',
  appSecret: process.env.FIDUCY_APP_SECRET!,
  storage: keyValueStorage(driver),
  getUserID: (request) => readSession(request)?.userID ?? null,
  basePath: '/api/fiducy' // optional, this is the default
});
OptionTypeNotes
gatewayURLstringYour gateway, for example https://gw.fiducy.dev
appSecretstringfsk_... from the dashboard. Server only
storageFiducyStorageWhere handles (and records) live. See Storage
getUserID(request) => string | nullYour signed-in user. May be async
basePathstringWhere the handler is mounted. Default /api/fiducy
fetchtypeof fetchOptional, for tests

fiducy.handler(request)

A standard Request => Response handler. Mount it under basePath in any framework.

RouteBodyResult
GET {basePath}/keys{ data: UserKeySummary[] }
POST {basePath}/keys{ provider, handle, record? }201 { data: UserKeySummary }
DELETE {basePath}/keys/:keyID{ data: { keyID } }
  • Every route answers 401 when getUserID returns null.
  • POST and DELETE answer 403 when the request's Origin is a different site.
  • Saving a key for a provider replaces and revokes that user's previous key for the same provider.

Without the Farm integration, mount it yourself:

app/api/fiducy/[...path]/route.ts
export const GET = fiducy.handler;
export const POST = fiducy.handler;
export const DELETE = fiducy.handler;

fiducy.providerSettings(provider, { userID })

Returns settings for the AI SDK provider factories, or null when the user has no key for that provider.

const settings = await fiducy.providerSettings('anthropic', { userID });
// { baseURL: 'https://gw.fiducy.dev/anthropic/v1', apiKey: 'fsk_...', headers: { 'x-key-handle': 'kh_...' } }
const anthropic = createAnthropic(settings!);

Providers: openai, anthropic, gemini, openrouter.

Other methods

await fiducy.listKeys(userID);                         // UserKeySummary[]
await fiducy.saveKey(userID, { provider, handle });    // UserKeySummary
await fiducy.revokeKey(userID, keyID);                 // boolean

UserKeySummary is { keyID, provider, createdAt }. Handles never leave your server through these methods.

Low-level client

For scripts or custom flows, @fiducy/sdk exports createGatewayClient({ gatewayURL, appSecret }) with providerSettings(provider, handle) and revokeKey(handle).