Call Confidential Inference from the OpenAI SDK
Point the official OpenAI Python or Node.js client at https://api.confidential.ai/v1 and keep the rest of your code. Chat, streaming, structured output and tools work unchanged.
Confidential Inference is OpenAI-compatible. The OpenAI SDK works with two changes: the base URL and the API key.
Prerequisites
- A Confidential AI API key. Keys are issued by email: request access or write to hello@confidential.ai.
- Python 3.8+ or Node.js 18+.
Set the key and base URL
export CONFIDENTIAL_API_KEY='<API_KEY>'| Setting | Value |
|---|---|
| Base URL | https://api.confidential.ai/v1 |
| API key | your Confidential AI key, sent as Authorization: Bearer |
| Model | an exact ID from GET /v1/models, e.g. deepseek-ai/DeepSeek-V4-Flash-0731 |
Make a request
Python:
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.confidential.ai/v1",
api_key=os.environ["CONFIDENTIAL_API_KEY"],
)
resp = client.chat.completions.create(
model="deepseek-ai/DeepSeek-V4-Flash-0731",
messages=[{"role": "user", "content": "Explain remote attestation in one sentence."}],
)
print(resp.choices[0].message.content)Node.js:
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.confidential.ai/v1",
apiKey: process.env.CONFIDENTIAL_API_KEY,
});
const resp = await client.chat.completions.create({
model: "deepseek-ai/DeepSeek-V4-Flash-0731",
messages: [{ role: "user", content: "Explain remote attestation in one sentence." }],
});
console.log(resp.choices[0].message.content);Stream the response
stream = client.chat.completions.create(
model="deepseek-ai/DeepSeek-V4-Flash-0731",
messages=[{"role": "user", "content": "Count to five."}],
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")response_format (JSON and strict JSON schema) and tools work as in the OpenAI API. Field details: API reference.
Verify before sending sensitive input
The SDK doesn't check attestation. Fetch /attestation with a fresh nonce and verify it before you send anything sensitive: Attestation.
How you know it worked
The request returns a normal chat completion. A 401 means the key is missing or wrong. A model error means the ID doesn't match GET /v1/models exactly.