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

with LatentKit(api_key="YOUR_RAW_KEY") as client:
    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.code, exc.body)

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())

Client options

  • api_key is required.
  • base_url defaults to https://ai.latentkit.com and is normalized to /v1.
  • timeout defaults to 120.0.
  • headers lets you add extra request headers.
  • http_client lets you inject a custom httpx.Client or httpx.AsyncClient.

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 directly to ask the assigned policy for a speed/depth tradeoff:

from latentkit import LatentKit

with LatentKit(api_key="YOUR_RAW_KEY") as client:
    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.

Chat, image, and embeddings

from latentkit import LatentKit

with LatentKit(api_key="YOUR_RAW_KEY") as client:
    chat = client.chat.create(
        messages=[{"role": "user", "content": "Write one sentence about LatentKit."}],
    )
    image = client.image.generate(prompt="A clean product icon", size="1024x1024")
    vectors = client.embeddings.create(input=["hello world"], dimensions=256)

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)

Supported resources

  • client.chat.create(...)
  • client.chat.stream(...)
  • client.completions.create(...)
  • client.completions.stream(...)
  • client.vision.create(...)
  • client.vision.stream(...)
  • client.embeddings.create(...)
  • client.image.generate(...)
  • client.speech.create(...)
  • client.transcription.create(...)
  • client.translation.create(...)
  • client.video.generate(...)
  • client.queue.create(...)
  • client.agents.sessions.create(...)

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.2.tar.gz (8.7 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.2-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: latentkit-0.1.2.tar.gz
  • Upload date:
  • Size: 8.7 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.2.tar.gz
Algorithm Hash digest
SHA256 f4e65dec176b8d3bd1aac63b2335ca5a6097276b465ea70f3678839213b663b9
MD5 5eb0d43bc49f01ad959839af6e904bdd
BLAKE2b-256 04d8db82bb5f2f684bc7418bd028db9348d5b7a8bcac5580a5dcca5a84aebb68

See more details on using hashes here.

File details

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

File metadata

  • Download URL: latentkit-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 14.5 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d3ff5ccae425ecb6ff1d448a9ac91f5cd4d22a3dba0d8a08185ee62f403758a8
MD5 62378d887cc634e7a60d9931c325d3d9
BLAKE2b-256 d2af95e5cb40e27072872e5838b79ec0b7bc289f06cb57be49c97a69898f5662

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