Call Confidential Inference from the Vercel AI SDK
Register Confidential Inference as an OpenAI-compatible provider in the Vercel AI SDK with @ai-sdk/openai-compatible, then use generateText and streamText as usual.
The Vercel AI SDK talks to Confidential Inference through its OpenAI-compatible provider.
Prerequisites
- A Confidential AI API key. Keys are issued by email: request access or write to hello@confidential.ai.
CONFIDENTIAL_API_KEYset in your environment.- Node.js 22+. Keep it server-side: never ship it to the browser.
Checked on 2 November 2026 with ai 7.0.159 and @ai-sdk/openai-compatible 3.0.82.
Create the provider
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
export const confidential = createOpenAICompatible({
name: "confidential",
baseURL: "https://api.confidential.ai/v1",
apiKey: process.env.CONFIDENTIAL_API_KEY,
});Generate or stream text
import { generateText, streamText } from "ai";
import { confidential } from "./confidential";
const { text } = await generateText({
model: confidential("deepseek-ai/DeepSeek-V4.1-Flash-1017"),
prompt: "Explain remote attestation in one sentence.",
});
const result = streamText({
model: confidential("deepseek-ai/DeepSeek-V4.1-Flash-1017"),
prompt: "Count to five.",
});
for await (const part of result.textStream) process.stdout.write(part);Use an exact model ID from GET /v1/models. Tools and structured output map onto the API's tools and response_format: API reference.
Verify before sending sensitive input
The client does not check attestation. Follow the attestation guide to configure and start TEErminator with the reviewed production pins. Before sending sensitive input, change the provider's baseURL to http://127.0.0.1:8080/v1. Keep the same API key. TEErminator verifies the upstream connection before forwarding requests.
How you know it worked
generateText returns text and streamText yields chunks. For a 401, read the error code: invalid_api_key indicates an authentication failure; model_not_authorized means a listed model ID is required.