View on GitHub
tinfoilsh/tinfoil-js
Overview
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).Installation
Quick Start
Do not set
baseURL unless you are routing through your own proxy server.Migration from OpenAI
Migrating from OpenAI to Tinfoil is straightforward. The client is designed to be compatible with the OpenAI Node client:TinfoilAI extends the standard OpenAI client.
Browser Support
The SDK supports browser environments for direct API access from web applications.Browser Usage
- Modern browsers with ES2020 support
- Web Crypto API support for enclave verification
Running the Chat Example
To run the streaming chat example:- Clone the repository
- Install dependencies:
- Create a
.envfile with your configuration:
- Run the example:
Usage
Model Examples
Below are specific examples for each supported model. Click on any model to see its configuration and usage example.Chat Models

GLM-5.2
GLM-5.2

Qwen3-VL 30B
Qwen3-VL 30B

Llama 3.3 70B
Llama 3.3 70B

GPT-OSS 120B
GPT-OSS 120B

Kimi K2.5
Kimi K2.5
Audio Models
Embedding Models

Nomic Embed Text
Nomic Embed Text
API Documentation
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.Advanced
Transport Modes
The SDK supports two transport modes via thetransport option:
'ehbp'(default): HPKE encryption via the Encrypted HTTP Body Protocol'tls': TLS certificate pinning (requires direct connection to the enclave)
SecureClient
For custom integrations, the SDK exposes aSecureClient class with low-level access to the secure transport layer and verification information:

