Skip to main content

View on GitHub

tinfoilsh/tinfoil-rs

Overview

The Tinfoil Rust SDK is a thin wrapper around the async-openai crate that provides secure communication with Tinfoil enclaves. It uses the same types and request/response shapes as async-openai and adds automatic verification that the endpoint is running in a secure Tinfoil enclave, TLS certificate pinning, and attestation validation.

Installation

New to Rust? Start here - Project Setup

If you don’t have a Cargo project yet, create one:
The minimum supported Rust version is 1.87.
Add the SDK and a runtime to Cargo.toml:

Migration from async-openai

Migrating from async-openai to Tinfoil is a small change — the SDK exposes the same chat / audio / embeddings handlers under tinfoil::Client:
tinfoil::Client derefs to async_openai::Client, so all OpenAI methods (client.chat(), client.embeddings(), client.audio(), …) work unchanged.

Usage

The common request/response types live under tinfoil::chat, tinfoil::audio, and tinfoil::embeddings — all re-exports of the corresponding async_openai::types::* modules.

Model Examples

Below are specific examples for current Tinfoil model categories.

Chat Models

Audio Models

Transcription

The transcribe shortcut on Client forwards to client.audio().transcription().create(request).

Audio Q&A

Embedding Models

The embed_batch shortcut takes a list of strings, preserves input order, and returns Vec<Vec<f32>>.

Vendor Extensions

Tinfoil exposes a few request/response fields the upstream OpenAI schema does not (for example web_search_options, pii_check_options, structured-output regex / choice constraints, and custom finish_reason values). To use them without async-openai rejecting the response, send the request through client.chat_relaxed():
Streaming uses the same builder and surfaces vendor-specific events (such as web_search_call) verbatim:

Advanced Functionality

For advanced use cases requiring manual verification or direct HTTP access, use SecureClient:

API Documentation

This library is a thin wrapper around the async-openai crate that can be used with Tinfoil. All methods and types are identical. See the async-openai documentation for complete API usage.