The Tinfoil JavaScript SDK is a wrapper around the OpenAI Node client that provides secure communication with Tinfoil enclaves. It has the same API as the OpenAI SDK with additional security features including automatic verification that the endpoint is running in a secure Tinfoil enclave, TLS certificate pinning, and attestation validation.All payloads are encrypted end-to-end using EHBP (Encrypted HTTP Body Protocol), which encrypts data directly to the attested enclave using HPKE (RFC 9180).
The SDK supports browser environments, allowing you to use the secure enclave-backed API directly from web applications.
Security Warning: Using API keys directly in the browser exposes them to anyone who can view your page source. For production applications, always use a backend server to handle API keys.
// 1. Create a clientconst client = new TinfoilAI({ apiKey: process.env.TINFOIL_API_KEY,});// 2. Use client as you would OpenAI client // see https://github.com/openai/openai-node for API documentation
import { TinfoilAI } from 'tinfoil';const client = new TinfoilAI({ apiKey: process.env.TINFOIL_API_KEY});// Example: Multi-step agentic workflowconst response = await client.chat.completions.create({ model: 'kimi-k2-thinking', messages: [ { role: 'user', content: 'Write a TypeScript function to validate email addresses using regex, then test it with several examples and debug any issues.' } ]});console.log(response.choices[0]?.message?.content);
DeepSeek R1
Copy
Ask AI
import { TinfoilAI } from 'tinfoil';const client = new TinfoilAI({ apiKey: process.env.TINFOIL_API_KEY});// Example: Complex reasoning taskconst response = await client.chat.completions.create({ model: 'deepseek-r1-0528', messages: [ { role: 'user', content: 'Solve this step by step: If a train travels 120 miles in 2 hours, and then increases its speed by 25% for the next 3 hours, how far does it travel in total?' } ]});console.log(response.choices[0]?.message?.content);
Qwen3-VL 30B
Copy
Ask AI
import { TinfoilAI } from 'tinfoil';import fs from 'fs';const client = new TinfoilAI({ apiKey: process.env.TINFOIL_API_KEY});// Example: Image analysisconst imageBuffer = fs.readFileSync('image.jpg');const base64Image = imageBuffer.toString('base64');const response = await client.chat.completions.create({ model: 'qwen3-vl-30b', messages: [ { role: 'user', content: [ { type: 'text', text: "What's in this image?" }, { type: 'image_url', image_url: { url: `data:image/jpeg;base64,${base64Image}` } } ] as any } ]});console.log(response.choices[0]?.message?.content);
Llama 3.3 70B
Copy
Ask AI
import { TinfoilAI } from 'tinfoil';const client = new TinfoilAI({ apiKey: process.env.TINFOIL_API_KEY});// Example: Conversational AIconst response = await client.chat.completions.create({ model: 'llama3-3-70b', messages: [ { role: 'user', content: 'What are the key differences between renewable and non-renewable energy sources?' } ]});console.log(response.choices[0]?.message?.content);
GPT-OSS 120B
Copy
Ask AI
import { TinfoilAI } from 'tinfoil';const client = new TinfoilAI({ apiKey: process.env.TINFOIL_API_KEY});// Example: Advanced reasoning with configurable effort levelsconst response = await client.chat.completions.create({ model: 'gpt-oss-120b', messages: [ { role: 'user', content: 'Analyze the trade-offs between different database architectures for a high-traffic e-commerce platform.' } ]});console.log(response.choices[0]?.message?.content);
Kimi K2.5
Copy
Ask AI
import { TinfoilAI } from 'tinfoil';const client = new TinfoilAI({ apiKey: process.env.TINFOIL_API_KEY});// Example: Native multimodal agentic codingconst response = await client.chat.completions.create({ model: 'kimi-k2-5', messages: [ { role: 'user', content: 'Review this codebase and suggest architectural improvements for better modularity and testability.' } ]});console.log(response.choices[0]?.message?.content);
This library is a drop-in replacement for the official OpenAI Node.js client that can be used with Tinfoil. All methods and types are identical. See the OpenAI client for complete API usage and documentation.
The SDK supports three transport modes via the transport option:
'auto' (default): Uses EHBP (end-to-end encryption), automatically switches to TLS in unsupported environments
'ehbp': Forces EHBP mode
'tls': Forces TLS certificate pinning mode
Copy
Ask AI
// TinfoilAI clientconst client = new TinfoilAI({ apiKey: process.env.TINFOIL_API_KEY, transport: 'auto' // or 'ehbp' or 'tls'});// SecureClient (low-level)const secureClient = new SecureClient({ transport: 'tls'});
EHBP is the preferred transport as it works in browsers and supports reverse proxies. TLS mode uses certificate pinning which only works in Node.js environments. See the EHBP documentation for details.