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. Keep it server-side: never ship it to the browser.
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-Flash-0731"),
prompt: "Explain remote attestation in one sentence.",
});
const result = streamText({
model: confidential("deepseek-ai/DeepSeek-V4-Flash-0731"),
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 AI SDK doesn't check attestation. Fetch /attestation with a fresh nonce and verify it first: Attestation.
How you know it worked
generateText returns text and streamText yields chunks. A 401 means the key is missing or wrong.