Python client for Tinfoil
Actively maintained. Last release 1 day ago, commits in 15 of the last 26 weeks. A safe choice.
pip install tinfoilREADME as published on PyPI with version 0.15.0.
Tinfoil Python Client
A Python client for verifiably private AI inference with Tinfoil. It wraps the OpenAI Python client with the same API, and before sending any request it verifies the enclave's attestation and encrypts the request body to the attested key using EHBP, so only the verified enclave can read it.
For complete documentation, see the Python SDK documentation.
Installation
uv add tinfoil
# or
pip install tinfoil
Quick Start
import os
from tinfoil import TinfoilAI
client = TinfoilAI(api_key=os.environ["TINFOIL_API_KEY"])
# Enclave verification and encryption happen automatically.
chat_completion = client.chat.completions.create(
model="llama3-3-70b", # see https://docs.tinfoil.sh/models/catalog
messages=[{"role": "user", "content": "Hi"}],
)
print(chat_completion.choices[0].message.content)
Async and streaming
Use AsyncTinfoilAI and await each call; the API is otherwise identical.
import asyncio
import os
from tinfoil import AsyncTinfoilAI
client = AsyncTinfoilAI(api_key=os.environ["TINFOIL_API_KEY"])
async def main() -> None:
stream = await client.chat.completions.create(
model="llama3-3-70b",
messages=[{"role": "user", "content": "Say this is a test"}],
stream=True,
)
async for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content is not None:
print(chunk.choices[0].delta.content, end="", flush=True)
print()
asyncio.run(main())