Call Confidential Inference from LangChain
Use ChatOpenAI from langchain-openai (Python) or @langchain/openai (JavaScript) with base URL https://api.confidential.ai/v1 to run LangChain chains and agents on confidential inference.
LangChain's OpenAI chat model works against Confidential Inference. Set the base URL and API key; chains, tools and agents built on ChatOpenAI run unchanged.
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.
Create the chat model
Python:
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="deepseek-ai/DeepSeek-V4-Flash-0731",
base_url="https://api.confidential.ai/v1",
api_key=os.environ["CONFIDENTIAL_API_KEY"],
)
print(llm.invoke("Explain remote attestation in one sentence.").content)JavaScript:
import { ChatOpenAI } from "@langchain/openai";
const llm = new ChatOpenAI({
model: "deepseek-ai/DeepSeek-V4-Flash-0731",
apiKey: process.env.CONFIDENTIAL_API_KEY,
configuration: { baseURL: "https://api.confidential.ai/v1" },
});
const msg = await llm.invoke("Explain remote attestation in one sentence.");
console.log(msg.content);Use an exact model ID from GET /v1/models.
Use it in chains and agents
llm is a standard LangChain chat model: pass it to prompts, bind_tools, with_structured_output or an agent constructor as you would any ChatOpenAI instance. Tool calling and JSON schema output are supported: API reference.
Verify before sending sensitive input
LangChain doesn't check attestation. Fetch /attestation with a fresh nonce and verify it first: Attestation.
How you know it worked
invoke returns an AIMessage with content. A 401 means the key is missing or wrong.
Prompts are protected from our side of the connection. Anything your chain logs or traces (for example to a tracing service) leaves your process in plaintext, so treat tracing as part of your own trust boundary.