New to Tinfoil? Get started in two steps:

  1. Install the SDK for your language:

    pip install tinfoil  # Python
    npm install tinfoil  # Node.js
    
  2. Create a client with your API key:

    Python
    from tinfoil import TinfoilAI
    client = TinfoilAI(api_key="<API_KEY>")
    
    Node.js
    import { TinfoilAI } from "tinfoil"
    const client = new TinfoilAI({ apiKey: "<API_KEY>" })
    

That’s it! The SDK handles attestation verification and follows the OpenAI interface—just change OpenAITinfoilAI in your imports and you’re done.

Security Warning: Never share your API key, be careful to not include it in version control systems, and never bundle it in with front-end client code.

Client Libraries

Tinfoil provides client-side SDKs in multiple languages to help you integrate with our API:

LanguageInstallationGitHub
Pythonpip install tinfoiltinfoil-python
Node.jsnpm install tinfoiltinfoil-node
SwiftAdd to dependencies: .package(url: "https://github.com/tinfoilsh/tinfoil-swift", from: "1.0.0")tinfoil-swift
Gogo get github.com/tinfoilsh/tinfoil-gotinfoil-go

Each library provides a drop-in replacement for the OpenAI client libraries:

  • Python: TinfoilAI supports the same interface as the OpenAI Python client
  • Node.js: TinfoilAI supports the same interface as the OpenAI Node client
  • Swift: TinfoilKit supports the same interface as the OpenAIKit Swift client
  • Go: tinfoil supports the same interface as the openai Go client

Code Examples

Each SDK follows the same interface as its OpenAI counterpart, making it easy to switch from OpenAI to Tinfoil. Just update your imports and API key—the rest of your code stays the same.

The examples below use deepseek-r1-70b, but the same code works with any model currently offered on Tinfoil. See Models & Code Examples for the full list of available models and their capabilities.

Python

The Python SDK is compatible with the OpenAI Python library:

from tinfoil import TinfoilAI

client = TinfoilAI(api_key="<API_KEY>")
chat = client.chat.completions.create(
    model="deepseek-r1-70b",  # or any other model
    messages=[{"role": "user", "content": "Hello!"}]
)

Node.js

The Node.js SDK matches the OpenAI Node library interface:

import { TinfoilAI } from "tinfoil"

const client = new TinfoilAI({ apiKey: "<API_KEY>" })
const chat = await client.chat.completions.create({
    model: "deepseek-r1-70b",
    messages: [{ role: "user", content: "Hello!" }]
})

Swift

Compatible with OpenAIKit:

import TinfoilKit

let client = TinfoilAI(apiKey: "<API_KEY>")
let chat = try await client.chat.completions.create(
    model: "deepseek-r1-70b",
    messages: [.user(content: "Hello!")]
)

Go

The Go SDK follows the OpenAI Go library patterns:

import "github.com/tinfoilsh/tinfoil-go"

client := tinfoil.NewClient("<API_KEY>")
chat, err := client.Chat.Completions.Create(context.TODO(), 
    openai.ChatCompletionRequest{
        Model: "deepseek-r1-70b",
        Messages: []openai.Message{
            {Role: "user", Content: "Hello!"},
        },
    },
)

CLI

The Tinfoil CLI provides a simple interface for quick tests:

# Install
curl -fsSL https://github.com/tinfoilsh/tinfoil-cli/raw/main/install.sh | sh

# Use
tinfoil chat -m deepseek-r1-70b "Hello!"

# Audio transcription
tinfoil audio -k <API_KEY> -m whisper-large-v3-turbo -f /path/to/audio.mp3

For model-specific examples (chat, embeddings, audio) and advanced configuration options, see the Models & Code Examples page.

Setting credentials via environment variables

All SDKs automatically pick up the following variables (handy for CI):

VariableDescription
TINFOIL_API_KEYYour secret API key
TINFOIL_BASE_URLOverride the default base URL at runtime (optional)

Example:

export TINFOIL_API_KEY="sk-..."
export TINFOIL_BASE_URL="https://llama3-3-70b-p.model.tinfoil.sh/v1/"
python my_private_app.py