Skip to main content

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

Requirements: Node 20+

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:
All method signatures remain the same since TinfoilAI extends the standard OpenAI client.

Browser Support

The SDK supports browser environments for direct API access 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.

Browser Usage

Browser Requirements:
  • Modern browsers with ES2020 support
  • Web Crypto API support for enclave verification

Running the Chat Example

To run the streaming chat example:
  1. Clone the repository
  2. Install dependencies:
  1. Create a .env file with your configuration:
  1. Run the example:
The example demonstrates streaming chat completions with the Tinfoil API wrapper.

Usage

Model Examples

Below are specific examples for each supported model. Click on any model to see its configuration and usage example.

Chat Models

Audio Models

Transcription

Audio Q&A

Embedding Models

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 the transport option:
  • 'ehbp' (default): HPKE encryption via the Encrypted HTTP Body Protocol
  • 'tls': TLS certificate pinning (requires direct connection to the enclave)
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.

SecureClient

For custom integrations, the SDK exposes a SecureClient class with low-level access to the secure transport layer and verification information: