proxy
@providerprotocol/ai / proxy
Proxy provider for UPP (Unified Provider Protocol)
This module exports the proxy provider for transporting PP requests over HTTP to a backend server, plus server-side utilities for implementing proxy endpoints.
Examples
Section titled “Examples”import { proxy } from '@providerprotocol/ai/proxy';import { llm } from '@providerprotocol/ai';
const backend = proxy({ endpoint: '/api/ai' });const instance = llm({ model: backend('default') });
const turn = await instance.generate('Hello!');import { llm, anthropic } from '@providerprotocol/ai';import { parseBody, toJSON, toSSE, toError } from '@providerprotocol/ai/proxy';
Bun.serve({ async fetch(req) { if (req.method === 'POST' && new URL(req.url).pathname === '/api/ai') { try { const { messages, system, params } = parseBody(await req.json()); const instance = llm({ model: anthropic('claude-sonnet-4-20250514'), system, params: { max_tokens: 4096, ...params }, });
const wantsStream = req.headers.get('accept')?.includes('text/event-stream'); if (wantsStream) { return toSSE(instance.stream(messages)); } return toJSON(await instance.generate(messages)); } catch (e) { return toError(e.message, 400); } } return new Response('Not found', { status: 404 }); }});Interfaces
Section titled “Interfaces”- AdapterOptions
- ParsedBody
- ParsedEmbeddingRequest
- ParsedImageRequest
- ParsedRequest
- ProxyEmbeddingParams
- ProxyImageParams
- ProxyLLMParams
- ProxyProviderOptions
- ProxyRequestOptions
- RequestMeta
Type Aliases
Section titled “Type Aliases”Variables
Section titled “Variables”Functions
Section titled “Functions”- bindTools
- deserializeMessage
- deserializeStreamEvent
- parseBody
- parseEmbeddingBody
- parseImageBody
- proxy
- proxyModel
- serializeMessage
- serializeStreamEvent
- serializeTurn
- toEmbeddingJSON
- toError
- toImageJSON
- toImageSSE
- toJSON
- toSSE
References
Section titled “References”TurnJSON
Section titled “TurnJSON”Re-exports TurnJSON