Skip to main content

Python client for the LatentKit gateway (OpenAI-compatible /v1 HTTP API).

Project description

LatentKit Python SDK

Official Python client for the canonical LatentKit /v1 API.

Install

pip install latentkit

Requires Python 3.10+.

Quickstart

from latentkit import LatentKit, LatentKitAPIError

client = LatentKit(api_key="YOUR_RAW_KEY")
try:
    response = client.chat.create(
        messages=[{"role": "user", "content": "Say hello from LatentKit."}],
        max_tokens=100,
        response_profile="balanced",
    )
    print(response["content"])
except LatentKitAPIError as exc:
    print(exc.status_code, exc.body)
client.close()

Async

import asyncio

from latentkit import AsyncLatentKit


async def main() -> None:
    async with AsyncLatentKit(api_key="YOUR_RAW_KEY") as client:
        response = await client.completions.create(
            prompt="Write a short product description for LatentKit.",
            system="Respond in one sentence.",
        )
        print(response["content"])


asyncio.run(main())

Timeouts and custom clients

LatentKit(...) and AsyncLatentKit(...) create httpx clients with a default timeout of 120s.

If you inject your own http_client, configure timeouts on that client yourself:

import httpx
from latentkit import LatentKit

http_client = httpx.Client(timeout=30.0)
client = LatentKit(api_key="YOUR_RAW_KEY", http_client=http_client)

Streaming

from latentkit import LatentKit

with LatentKit(api_key="YOUR_RAW_KEY") as client:
    for event in client.chat.stream(
        messages=[{"role": "user", "content": "Count from one to five."}],
    ):
        if event.event == "error":
            raise RuntimeError(event.data)
        if event.is_done:
            break
        print(event.data["delta"], end="")

Response profiles

Pass response_profile to ask the assigned policy for a speed/depth tradeoff:

response = client.chat.create(
    messages=[{"role": "user", "content": "Give me the short version."}],
    response_profile="fast",
)

Allowed values are fast, balanced, and deep. The assigned policy controls whether request overrides are allowed and which routes are eligible for each profile.

Agent sessions

from latentkit import LatentKit

with LatentKit(api_key="YOUR_RAW_KEY") as client:
    session = client.agents.sessions.create(
        task="Inspect the repo and explain the auth flow",
        workspace_root="/workspace",
        permission_mode="workspace-write",
    )
    queued = client.agents.sessions.run(session["id"])
    print(queued)

See docs/latentkit-coder-api.md for the full agent session request/response model.

Modalities

with LatentKit(api_key="YOUR_RAW_KEY") as client:
    client.embeddings.create(input=["hello world"], dimensions=256)
    client.image.generate(prompt="A clean product icon", size="1024x1024")
    client.speech.create(input="Hello from LatentKit.", voice="alloy")
    client.transcription.create(audio={"base64": "..."}, language="en")
    client.translation.create(audio={"base64": "..."}, target_language="en")
    client.video.generate(prompt="A short product scene", duration_seconds=4)

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

latentkit-0.1.1.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

latentkit-0.1.1-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file latentkit-0.1.1.tar.gz.

File metadata

  • Download URL: latentkit-0.1.1.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for latentkit-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cd0b3b5467a3057bef44b6261410ec2ab1bc182ea92536671fa87b1ebac861ba
MD5 5eed06b7e0e840718ae69af0e082933f
BLAKE2b-256 6b2aa5ba75371b2a8f450c8aa12a874c40d4ec2fde2a9db8d1f356fa1ad6d2b0

See more details on using hashes here.

File details

Details for the file latentkit-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: latentkit-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for latentkit-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 90f46e4da3e7a04da0a640f08602c50adefaee00235b8e239d90e245eaf02390
MD5 319c2b50bfce1928435ff451631fcd7a
BLAKE2b-256 752805308e1d8685bafa6f2c8f41c482545a1b80edc0fa1f31e105c268b5243e

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