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.
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(...)
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file latentkit-0.2.1.tar.gz.
File metadata
- Download URL: latentkit-0.2.1.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
191ef25e812541383507a54b8f4adb3bde61baf47077a6f1f2339fe71dd49a59
|
|
| MD5 |
5a45f6edc49d54647c4e696c5a28dc19
|
|
| BLAKE2b-256 |
bf4d9111c64928a2c15b457f9230479517fda6225be540d5a322357d946c9041
|
File details
Details for the file latentkit-0.2.1-py3-none-any.whl.
File metadata
- Download URL: latentkit-0.2.1-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58a007c623a796525821c99088c5b267ae8a10c4fa005fe70d2b7c60f653f4e6
|
|
| MD5 |
886ab8ce47db80e63604e3afbae88978
|
|
| BLAKE2b-256 |
10031b5da4e6078313899abab9ef0c775ac58cbd37e9785a955b2eef405272f2
|