Skip to content
Reference

Python SDK

VAKYN has no SDK of its own. Use TypeSafe's official Python package, typesafe-sdk, and point it at VAKYN MAX or your own server.

Install

pip install typesafe-sdk   # Python 3.10 or newer

The examples here were run against open-server with typesafe-sdk 0.7.2. The package's own reference is at docs.typesafe.ai.

Point it at VAKYN

The client reads its settings from the environment, so existing code needs no change: set the base URL to VAKYN and use a key issued there.

VariableSet toDefault
TYPESAFE_BASE_URLhttps://api.vakyn.com for VAKYN MAX, or your server, e.g. http://localhost:8080 (no /v1)https://api.typesafe.ai
TYPESAFE_API_KEYa vk_… key from the console (VAKYN MAX) or from your servernone, required
TYPESAFE_DEFAULT_MODELleave unset, or a name from models.list()jev-latest
TYPESAFE_LOG_LEVELdebug, info, … to log requestsunset

Or pass the same settings to the constructor; explicit arguments win over the environment:

from typesafe_sdk import RetryPolicy, TypeSafeClient client = TypeSafeClient(    base_url="https://api.vakyn.com",  # VAKYN MAX, without /v1    api_key="vk_your_key_here",  # from vakyn.com/console/keys    timeout=30.0,  # seconds per attempt    retry=RetryPolicy(max_retries=4),  # 429 and 5xx are retried)print([m.name for m in client.models.list().models])

Ask questions

system_one(state, questions) sends one request. Questions are Noul, Choice and Score objects, or plain dicts in the wire format. The result gives typed access by question type:

from typesafe_sdk import Choice, Noul, Score, TypeSafeClient # Reads TYPESAFE_BASE_URL (https://api.vakyn.com) and TYPESAFE_API_KEY from the environment.client = TypeSafeClient()result = client.system_one(    state={        "channel": "email",        "customer": {"plan": "team", "seats": 12, "months_active": 14},        "message": "Since this morning nobody on our team can sign in. We have a client demo at 3pm.",    },    questions={        "outage": Noul(instructions="Is the customer unable to use the product?"),        "team": Choice(            instructions="Which team should handle this?",            criteria={                "billing": "Invoices, charges and refunds",                "access": "Sign-in, passwords and permissions",                "product": "Bugs and how-to questions",            },        ),        "urgency": Score(            instructions="How soon does this need a reply?",            criteria=["Can wait", "Today", "Within the hour"],        ),    },)print(result.nouls["outage"].noul, result.choices["team"].choice, result.scores["urgency"].score)
Try it in the playground
  • result.nouls[name].noul, result.choices[name].choice / .confidence / .probabilities, result.scores[name].score / .legend / .probabilities / .confidence (score keys are integers here).
  • result.answers holds all answers in request order; result.model, result.usage.input_tokens and result.request_id describe the call.
  • client.models.list().models lists the model and the jev-latest alias.

Async

AsyncTypeSafeClient has the same methods as coroutines. Use it to send many requests concurrently; the server queues them.

import asyncio from typesafe_sdk import AsyncTypeSafeClient, Noul MESSAGES = [    "Where is my parcel?",    "Please cancel my subscription at the end of the month.",    "Your app crashes when I open settings.",]  async def main() -> None:    # Reads TYPESAFE_BASE_URL (https://api.vakyn.com) and TYPESAFE_API_KEY from the environment.    async with AsyncTypeSafeClient() as client:        # The server queues what it can take and answers 429 beyond that;        # the SDK retries 429 after the delay the server asks for.        results = await asyncio.gather(*(            client.system_one(state=m, questions={"cancel": Noul(instructions="Does the customer want to cancel?")})            for m in MESSAGES        ))    for m, r in zip(MESSAGES, results):        print(f"{r.nouls['cancel'].noul:.2f}  {m}")  asyncio.run(main())

Errors and retries

Every non-2xx response raises a subclass of TypeSafeAPIError with status, body and request_id. See Errors for what each status means, including the 402 VAKYN MAX sends when the balance is empty.

from typesafe_sdk import (    Score,    TypeSafeAPIConnectionError,    TypeSafeAuthenticationError,    TypeSafeBadRequestError,    TypeSafeClient,    TypeSafeRateLimitError,    TypeSafeUnprocessableEntityError,) # Reads TYPESAFE_BASE_URL (https://api.vakyn.com) and TYPESAFE_API_KEY from the environment.client = TypeSafeClient()try:    result = client.system_one(        state="Rate this.",        questions={"rating": Score(criteria=[f"level {i}" for i in range(11)])},  # one level too many    )    print(result.request_id)except TypeSafeBadRequestError as e:  # 400: over a limit, or an unknown model    print(e.status, e.body["detail"], e.request_id)except TypeSafeUnprocessableEntityError as e:  # 422: the body does not match the schema    print(e.body["detail"])except TypeSafeAuthenticationError:  # 401: missing, wrong or revoked key    print("check TYPESAFE_API_KEY")except TypeSafeRateLimitError:  # 429 that outlasted the retries    print("server busy")except TypeSafeAPIConnectionError:  # no answer: wrong base URL, server down, timeout    print("cannot reach the server")

By default the client retries twice, with backoff, on 408, 429 and 5xx responses and on connection errors, and honors the server's retry-after. Tune it with RetryPolicy (for example RetryPolicy(max_retries=0) to turn retries off), on the client or per call.

Differences from TypeSafe's hosted API

  • Model names: jev-latest works; specific hosted names such as a dated Jev version do not. Use jev-latest or the name from models.list().
  • Keys start with vk_ and come from the VAKYN console or your own server; keys from other services do not work.
  • Requests, answers, limits and error bodies are the same as on the hosted API.

Loading the docs…