Skip to content

tinfoilsh/tinfoil-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

215 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tinfoil Rust Client

Build Status Documentation

For complete documentation, see the Rust SDK documentation.

Installation

Add to your Cargo.toml:

[dependencies]
tinfoil = { git = "https://github.com/tinfoilsh/tinfoil-rs" }
tokio = { version = "1", features = ["full"] }

Quick Start

The Tinfoil Rust client is a wrapper around async-openai and provides secure communication with Tinfoil enclaves. It has the same API as the async-openai client, with additional security features:

  • Automatic attestation validation to ensure enclave integrity verification
  • Supports a fallback mode with TLS certificate pinning using attested certificates to provide direct-to-enclave encrypted communication over TLS
use tinfoil::Client;
use tinfoil::chat::{
    ChatCompletionRequestUserMessageArgs, CreateChatCompletionRequestArgs,
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a client (reads TINFOIL_API_KEY from env)
    let client = Client::new_default().await?;

    // Make requests using the OpenAI client API
    // Note: enclave verification and direct-to-enclave encryption happens automatically
    let request = CreateChatCompletionRequestArgs::default()
        .model("llama3-3-70b")
        .messages(vec![
            ChatCompletionRequestUserMessageArgs::default()
                .content("Say this is a test")
                .build()?
                .into(),
        ])
        .build()?;

    let response = client.chat().create(request).await?;

    println!("{}", response.choices[0].message.content.as_ref().unwrap());

    Ok(())
}

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

Usage

// 1. Create a client (reads TINFOIL_API_KEY from env)
let client = Client::new_default().await?;

// 2. Use client as you would async_openai::Client
// see https://docs.rs/async-openai for API documentation

Advanced Functionality

use tinfoil::{Client, SecureClient};

// Create a client with explicit enclave and repo parameters
let client = Client::new(
    "enclave.example.com",
    "org/repo",
    "<YOUR_API_KEY>",
).await?;

// For direct HTTP access, use the underlying http_client
let http = client.http_client()?;
let resp = http
    .get(format!("https://{}/health", client.enclave()))
    .send()
    .await?;

API Documentation

This library is a drop-in replacement for async-openai that can be used with Tinfoil. All methods and types are identical. See the async-openai documentation for complete API usage and documentation.

Reporting Vulnerabilities

Please report security vulnerabilities by emailing security@tinfoil.sh.

We aim to respond to (legitimate) security reports within 24 hours.

About

Tinfoil Rust Client supporting the OpenAI API standard

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages