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.
Inspect the connected route
client.me.retrieve() and await client.me.retrieve() are typed as
MeResponse. The response includes connection, assigned route, ordered model,
credit, and latest winning request data when available:
context = client.me.retrieve()
route = context.get("policy")
if route:
print(route.get("name"), route.get("model_count"))
for model in route.get("models", []):
print(model.get("rank"), model.get("provider"), model.get("model"))
latest = context.get("latest_request")
if latest:
print(latest.get("model"))
The latest winner is request activity, not a permanently selected model. Runtime SDK credentials cannot change the assigned route.
Client options
api_keyis required.base_urldefaults tohttps://ai.latentkit.comand is normalized to/v1.timeoutdefaults to120.0.headerslets you add extra request headers.http_clientlets you inject a customhttpx.Clientorhttpx.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)
Queue requests support every endpoint accepted by POST /v1/queue and an optional idempotency key:
client.queue.create(
endpoint="embeddings",
payload={"input": ["hello world"]},
idempotency_key="import-row-42",
)
Queue support is enqueue-only. There is no public per-job result endpoint, so workflows that need results should use their host job runner and call a synchronous SDK resource from that job.
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(...)
Metadata
Release files for latentkit 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| latentkit-0.2.1.tar.gz | 13.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| latentkit-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.8 kB
Release files / latentkit-0.2.1.tar.gz
| Download URL | latentkit-0.2.1.tar.gz |
|---|---|
| Size | 13.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
191ef25e812541383507a54b8f4adb3bde61baf47077a6f1f2339fe71dd49a59
|
|
BLAKE2b-256 checksum How to use checksums |
bf4d9111c64928a2c15b457f9230479517fda6225be540d5a322357d946c9041
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / latentkit-0.2.1-py3-none-any.whl
| Download URL | latentkit-0.2.1-py3-none-any.whl |
|---|---|
| Size | 18.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
58a007c623a796525821c99088c5b267ae8a10c4fa005fe70d2b7c60f653f4e6
|
|
BLAKE2b-256 checksum How to use checksums |
10031b5da4e6078313899abab9ef0c775ac58cbd37e9785a955b2eef405272f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for latentkit 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.