Skip to main content

Python client for the route-based LatentKit /v1 API.

Project description

LatentKit Python SDK

Official Python client for the canonical LatentKit /v1 API.

Route-based by design: do not pass model, provider, route, or policy in SDK requests. The API key's assigned published route selects the provider/model at runtime.

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

Route-based requests

The SDK is not model-based. Your application sends the task body and optional response_profile; LatentKit resolves the provider/model from the API key's assigned route. model in a response is reporting metadata for the route that won, not a request field.

SDK calls reject route-control keys such as model, provider, route, and policy, including inside extra_body.

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.3.tar.gz (9.4 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.3-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for latentkit-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b7d16930bf99957857663d9724319e051204747110a2aa554c3227e2ec9d5237
MD5 d4a6da2599c6cd20343ef350a8f916d7
BLAKE2b-256 a8e2a9b7cbb80cbd1f05219a7fc75038102c9bd76fd05436f8bec8547cc0f1d5

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for latentkit-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 90851699c0a68aeda6348333459b845128787d0e14a534dc24098567339ed8eb
MD5 cc854f267ffd02968119739cc2a8f6f0
BLAKE2b-256 d7a659a3aed2178468cd053e8c4c1cc0093e1676b9bbe4c284da9c911d39e053

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