Kearnix developer guide ยท English

Call an uncensored AI model from Python

Install the Python OpenAI SDK, configure Kearnix's base URL, select a GLM, Qwen or DeepSeek model, and read a chat completion and token usage.

Install the client in an isolated environment

Use a supported Python version for the current openai package. Create a virtual environment, activate it using the command for your shell, and install the SDK. Save the request below as kearnix_demo.py. This is server-side Python; a Kearnix key should not be placed in a web page or committed to a repository.

python -m venv .venv
# macOS / Linux: source .venv/bin/activate
# PowerShell: .\.venv\Scripts\Activate.ps1
python -m pip install openai

Set your key and an exact model ID

Create an account, add prepaid credit and create an API key in the dashboard. Set KEARNIX_API_KEY and KEARNIX_MODEL in the same terminal that will run the script. For example, use z-ai/glm-5.3-flash-uncensored after checking its live model page. The values below are placeholders; replace the key before running.

# macOS / Linux
export KEARNIX_API_KEY='your-kearnix-key'
export KEARNIX_MODEL='z-ai/glm-5.3-flash-uncensored'

# PowerShell
$env:KEARNIX_API_KEY = 'your-kearnix-key'
$env:KEARNIX_MODEL = 'z-ai/glm-5.3-flash-uncensored'

Send a bounded chat request

Run python kearnix_demo.py after saving this example. It uses the Chat Completions client because the featured uncensored models currently list that endpoint. An output limit of 128 keeps the first test small; it does not reserve or charge 128 tokens automatically. The SDK timeout bounds how long this call waits.

import os
from openai import OpenAI

with OpenAI(
    api_key=os.environ["KEARNIX_API_KEY"],
    base_url="https://kearnix.com/v1",
    timeout=60.0,
    max_retries=0,
) as client:
    completion = client.chat.completions.create(
        model=os.environ["KEARNIX_MODEL"],
        messages=[{"role": "user", "content": "Say hello in one sentence."}],
        max_tokens=128,
    )
    print(completion.choices[0].message.content)
    if completion.usage:
        print("Tokens:", completion.usage.total_tokens)

Handle errors before adding traffic

The example disables automatic retries so the initial evaluation is easy to count. For a deployed application, catch openai.APIStatusError and openai.APIConnectionError. Correct invalid credentials, model IDs or insufficient-credit errors before retrying. Use bounded backoff for transient failures and avoid exposing provider error bodies or your key in client-visible logs.

This example's request path, authorization, model selection and response parsing are checked against a local OpenAI-compatible fixture. That check does not establish live model quality, latency or tool support. Run your own small funded request and inspect account usage before expanding a workload. SDK reference: https://github.com/openai/openai-python.

From choosing a model to your first request