Skip to main content

Private, verifiable AI inference on 0G chain — drop-in OpenAI-compatible SDK

Project description

zkai

OpenAI-compatible Python SDK for ZKai — private, verifiable AI inference on 0G chain.

ZKai sends your prompt through a Trusted Execution Environment (Intel TDX), encrypts it client-side so even the gateway cannot read it, and anchors a SHA-256 attestation of every inference on the 0G chain. You get back a normal OpenAI-style response plus an on-chain receipt.

Install

pip install zkai

Optional LangChain adapter:

pip install "zkai[langchain]"

Quick start

from zkai import ZKai

client = ZKai(api_key="zkai-...")  # get one at https://zkai-ether-og.vercel.app

response = client.chat.completions.create(
    model="qwen2.5:1.5b",
    messages=[{"role": "user", "content": "Hello!"}],
)

print(response.choices[0].message.content)
print("Attestation hash:", response.attestation_hash)

The response is decrypted locally — the gateway sees only ciphertext. The attestation hash is anchored on 0G mainnet and can be verified independently.

How it works (gateway mode, default)

  1. The SDK fetches the enclave's X25519 public key from the gateway.
  2. It encrypts your prompt locally with ECDH + ChaCha20-Poly1305.
  3. It sends only the ciphertext to the gateway.
  4. The gateway routes the opaque blob to a TDX-sealed enclave running the requested model.
  5. The enclave decrypts inside sealed memory, runs the model, encrypts the response, and emits a SHA-256 attestation hash.
  6. The attestation lands on the on-chain AttestationRegistry contract.
  7. The SDK decrypts the response locally and returns it to you.

End-to-end, the gateway never sees plaintext.

Configuration

ZKai(
    api_key="zkai-...",                             # issued from the dashboard
    base_url="https://zkai-ether-og.vercel.app",    # default
    encrypted=True,                                  # default; set False to use the legacy plaintext path
    provider_endpoint=None,                          # set to bypass gateway and hit a provider directly
    skip_attestation=False,                          # only for development; do not disable in prod
)
Argument Type Default Description
api_key `str None` None
base_url `str None` https://zkai-ether-og.vercel.app
encrypted bool True When True, prompts are encrypted client-side. Set False for legacy clients.
provider_endpoint `str None` None
skip_attestation bool False Disables attestation verification. Useful only for dev loops.

OpenAI compatibility

The response object mirrors OpenAI's chat completion shape:

response.id
response.model
response.choices[0].message.content
response.choices[0].finish_reason
response.usage.prompt_tokens
response.usage.completion_tokens

# ZKai-specific:
response.attestation_hash  # on-chain commitment

Drop-in replacement for most OpenAI SDK call sites — just swap the client class.

On-chain components (0G mainnet, chain ID 16661)

Contract Address
ProviderRegistry 0x6D400F5D1DcCaA3e98E3dE17322aA23DE38bAC99
PaymentEscrow 0xb2C7c0F7a4C2877319E8Ed1Fae0bf3C705b6Fc4C
AttestationRegistry 0x8c8Ae0A113084268D181fd1cf23d611DC2EAa2B2

Verify any attestation hash on the 0G explorer.

Running your own provider

See the companion zkai-cli package:

pip install zkai-cli
zkai init && zkai start && zkai register

Links

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zkai-0.5.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zkai-0.5.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file zkai-0.5.0.tar.gz.

File metadata

  • Download URL: zkai-0.5.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for zkai-0.5.0.tar.gz
Algorithm Hash digest
SHA256 b7e521766c0976053c740e82d141aad9c42850609769c6cf79f86f1f45e7dbad
MD5 f782d5e3133f5c395286afa7e74c3070
BLAKE2b-256 de8dadb6b13795580873f0a251a7bf23aac42804afb1839b04400aa171bc6764

See more details on using hashes here.

File details

Details for the file zkai-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: zkai-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for zkai-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 175ec362dd4cf001233df19ef9c646821d87d1008327e2eaebd9bad9f02e2c76
MD5 7de021b0fa265eb5466671ffd7ffa20c
BLAKE2b-256 fead2a2c74d8f6b89f94de8e6bf72e034aeb5454cc1302fbbfd01a0874791e5a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page