Skip to main content

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

Release files for zkai 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for zkai 0.5.0
File Size Uploaded
zkai-0.5.0.tar.gz 12.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for zkai 0.5.0
File Interpreter ABI Platform
zkai-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.1 kB

Release files / zkai-0.5.0.tar.gz

Download URL zkai-0.5.0.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b7e521766c0976053c740e82d141aad9c42850609769c6cf79f86f1f45e7dbad
BLAKE2b-256 checksum
How to use checksums
de8dadb6b13795580873f0a251a7bf23aac42804afb1839b04400aa171bc6764
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.2

Release files / zkai-0.5.0-py3-none-any.whl

Download URL zkai-0.5.0-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
175ec362dd4cf001233df19ef9c646821d87d1008327e2eaebd9bad9f02e2c76
BLAKE2b-256 checksum
How to use checksums
fead2a2c74d8f6b89f94de8e6bf72e034aeb5454cc1302fbbfd01a0874791e5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.2

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page