@dassi_ai/relay
v0.1.0
Published
Route pi-ai models through Relay LLM proxy
Readme
@dassi/relay
Route pi-ai models through the Relay LLM proxy for managed billing.
Install
npm install @dassi/relay @mariozechner/pi-aiUsage
import { relay } from '@dassi/relay';
import { streamSimple } from '@mariozechner/pi-ai';
// Get a Relay-routed model from a model ID
const model = relay('claude-sonnet-4-5');
// Or reroute an existing pi-ai Model
import { getModel } from '@mariozechner/pi-ai';
const relayModel = relay(getModel('anthropic', 'claude-sonnet-4-5'));
// Stream with your Supabase JWT as the API key
const stream = streamSimple(model, context, { apiKey: supabaseJwt });Custom Relay URL
For self-hosted Relay instances:
const model = relay('gpt-5.4', { relayUrl: 'https://my-relay.example.com' });API
relay(modelOrId, options?)
Returns a pi-ai Model with baseUrl pointing to Relay.
modelOrId:string(model ID like'claude-sonnet-4-5') or existing pi-aiModeloptions.relayUrl: Override the default Relay URL
detectProvider(modelId)
Detect the native provider from a model ID: claude-* -> anthropic, gemini-* -> google, else -> openai.
Constants
RELAY_URL— Default Relay proxy URLRELAY_PROVIDERS— Per-provider Relay endpoint URLs
How It Works
Relay is a transparent HTTP proxy. It never parses or modifies request/response bodies. The SDK:
- Detects the native provider from the model name (or Model's
apifield) - Gets the model from pi-ai's registry (using the native provider's SDK)
- Overrides
baseUrlto route through Relay
Your Supabase JWT is passed as the API key. Relay validates it, checks your budget, swaps in the real provider API key, and forwards the request.
