@tenzro/ai-provider
v0.4.15
Published
Tenzro AI provider authoring kit — types and helpers for implementing Tenzro-compatible inference providers (LanguageModelV2-shaped surface, stream parts, modality dispatch).
Downloads
157
Maintainers
Readme
@tenzro/ai-provider
Provider authoring kit for Tenzro-compatible inference providers.
Implement LanguageModelV2 to publish a provider package that plugs into @tenzro/ai. The interface matches Vercel AI SDK 6's LanguageModelV2 shape with three Tenzro-specific additions.
pnpm add @tenzro/ai-provider
# @tenzro/ai is a peer dep — your consumers will install it alongside.Tenzro deltas
A standard LanguageModelV2 provider works almost as-is. The Tenzro additions are:
TenzroProviderContexton the call options. Carries the caller'sSigner(TDIP DID + hybrid Ed25519 + ML-DSA-65) andPaymentSpec. Providers that gate on identity check the signed inference preimage; providers that charge per-token pass the payment authorization through to settlement.Three new stream-part types. Re-exported from
@tenzro/ai/types:tenzro-attestation— TEE quote (TDX / SEV-SNP / Nitro / NVIDIA-CC) with binding DID.tenzro-zk-proof— Plonky3 STARK over the inference IO.tenzro-payment-receipt— protocol-tagged settlement receipt (x402 / MPP / channel).
attestation,zkProof,paymentReceipton the generate result. The non-streaming counterpart of the new stream parts.
Multi-modal helpers (embed, forecast, transcribe, ...) live in @tenzro/ai and dispatch directly to the node JSON-RPC. Providers only implement the chat/completion surface.
Minimal provider
import type {
LanguageModelV2,
LanguageModelV2CallOptions,
LanguageModelV2GenerateResult,
LanguageModelV2StreamResult,
} from '@tenzro/ai-provider';
export function myModel(modelId: string): LanguageModelV2 {
return {
specificationVersion: 'v2',
provider: 'my-provider',
modelId,
supportedUrls: { '*/*': [/^https?:\/\//] },
async doGenerate(opts: LanguageModelV2CallOptions): Promise<LanguageModelV2GenerateResult> {
const res = await fetch('https://my-provider.example.com/v1/generate', {
method: 'POST',
headers: buildHeaders(opts.providerContext),
body: JSON.stringify({
model: modelId,
messages: opts.prompt,
temperature: opts.temperature,
max_tokens: opts.maxOutputTokens,
}),
signal: opts.abortSignal,
});
const data = await res.json();
return {
content: [{ type: 'text', text: data.text }],
finishReason: data.finish_reason ?? 'stop',
usage: {
inputTokens: data.usage.prompt_tokens,
outputTokens: data.usage.completion_tokens,
totalTokens: data.usage.total_tokens,
},
// Optional Tenzro additions:
attestation: data.attestation,
paymentReceipt: data.payment_receipt,
};
},
async doStream(opts: LanguageModelV2CallOptions): Promise<LanguageModelV2StreamResult> {
// Return a `ReadableStream<TenzroStreamPart>` driven by the provider's
// SSE endpoint. Emit `text-delta` / `reasoning-delta` / `tool-call` /
// `finish` as you would for a vanilla LanguageModelV2 provider, plus
// `tenzro-attestation` / `tenzro-zk-proof` / `tenzro-payment-receipt`
// when the underlying response carries them.
// ...
},
};
}TenzroProviderContext
Available on opts.providerContext for both doGenerate and doStream:
interface TenzroProviderContext {
readonly signer?: Signer; // Tenzro identity for this call
readonly payment?: PaymentSpec; // Caller's payment shape
}If your provider charges per-token, the typical flow is:
- Compute the canonical preimage with
computeInferencePreimagefrom@tenzro/ai. - Ask
signerfor{ ed25519, mlDsa65, did }over that preimage. - Forward the signature in your provider's auth header.
- Surface the settlement receipt as
paymentReceipton the result (ortenzro-payment-receiptstream part).
Publishing
Provider packages are published to npm under their own scope. Consumers install both packages:
npm install @tenzro/ai @your-org/ai-tenzro-providerThen construct the provider directly:
import { generateText } from '@tenzro/ai';
import { myModel } from '@your-org/ai-tenzro-provider';
const { text } = await generateText({
model: myModel('llama-3.3-70b'),
prompt: 'Hello.',
});@tenzro/ai's built-in tenzro() factory targets the network's discovery + routing layer — your provider package targets a single provider implementation directly.
Status
Pre-alpha. APIs may change without notice until 1.0.
License
Apache-2.0
