Skip to main content

Python SDK

Use the Lucid API from Python using standard HTTP libraries. Since TrustGate implements the OpenAI Chat Completions API, you can also use the official OpenAI Python SDK.
A dedicated Speakeasy-generated Python SDK is planned. In the meantime, the methods below provide full API access.
The simplest approach — use the official OpenAI Python package with Lucid’s base URL:
from openai import OpenAI

client = OpenAI(
    api_key="your-lucid-api-key",
    base_url="https://api.lucid.foundation/v1",
)

# Chat completion
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)

# Streaming
stream = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Write a haiku"}],
    stream=True,
)
for chunk in stream:
    content = chunk.choices[0].delta.content
    if content:
        print(content, end="", flush=True)

Option 2: httpx (Direct API)

For full API access beyond chat completions:
import httpx

BASE_URL = "https://api.lucid.foundation"
HEADERS = {"Authorization": "Bearer your-lucid-api-key"}

# List passports
response = httpx.get(f"{BASE_URL}/v1/passports", headers=HEADERS)
passports = response.json()

# Create a passport
response = httpx.post(f"{BASE_URL}/v1/passports", headers=HEADERS, json={
    "name": "my-agent",
    "type": "agent",
    "metadata": {"framework": "crewai"},
})
passport = response.json()

# Run chat completion
response = httpx.post(f"{BASE_URL}/v1/chat/completions", headers=HEADERS, json={
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Hello!"}],
})
result = response.json()

# Get receipt
receipt_id = result.get("receipt_id")
receipt = httpx.get(f"{BASE_URL}/v1/receipts/{receipt_id}", headers=HEADERS).json()
print(f"Verified: {receipt['signature_valid']}")

Option 3: requests

import requests

BASE_URL = "https://api.lucid.foundation"
session = requests.Session()
session.headers.update({"Authorization": "Bearer your-lucid-api-key"})

# List epochs
epochs = session.get(f"{BASE_URL}/v1/epochs").json()
for epoch in epochs["data"]:
    print(f"Epoch {epoch['id']}: {epoch['receiptCount']} receipts, anchored={epoch['anchored']}")

Verify Receipts in Python

from nacl.signing import VerifyKey
import httpx

client = httpx.Client(
    base_url="https://api.lucid.foundation",
    headers={"Authorization": "Bearer your-key"},
)

# Get the signer's public key
pubkey_hex = client.get("/v1/signer/pubkey").json()["publicKey"]
verify_key = VerifyKey(bytes.fromhex(pubkey_hex))

# Verify a receipt
receipt = client.get(f"/v1/receipts/{receipt_id}").json()
message = (receipt["id"] + receipt["inputHash"] + receipt["outputHash"] + receipt["timestamp"]).encode()
signature = bytes.fromhex(receipt["signature"])

try:
    verify_key.verify(message, signature)
    print("Receipt signature is valid")
except Exception:
    print("Invalid signature!")

API Reference

See the full REST API documentation for all available endpoints, or explore the API Reference for OpenAPI-generated docs.