Setup guide

Set up in about two minutes

Everything you need to connect a chat app or your own code to Krapi.

Quick start

You need three things. Paste them into your app's settings, or into your code.

  1. The base URL

    The web address your app sends messages to. Copy it and paste it into your app or code.

    Base URL
  2. Your API key

    A private code from the seller you got access from. Paste it into your app's "API key" field. Keep it secret, like a password.

  3. A model name

    The AI model to use, for example {{MODEL}}. The Test your key page lists the models your key can use.

One complete example

Choose where you'll use it. Replace YOUR_API_KEY with your key, and {{MODEL}} with a model from your list.

  1. In your app's settings, choose OpenAI, OpenAI-compatible or Custom endpoint.
  2. Paste the base URL into the "Base URL", "API base" or "Endpoint" field.
  3. Paste your API key into the "API key" field.
  4. Type or pick a model (the Test your key page lists yours), save, and send a message.

Field names differ between apps — see Use in apps for the common ones.

# cURL (command line): for macOS/Linux Terminal or Git Bash. On Windows, use the Python tab.
curl {{BASE_URL}}/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "{{MODEL}}",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'
# pip install openai
from openai import OpenAI

client = OpenAI(
    base_url="{{BASE_URL}}",
    api_key="YOUR_API_KEY",
)

reply = client.chat.completions.create(
    model="{{MODEL}}",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(reply.choices[0].message.content)
// npm install openai   (save as hello.mjs, run: node hello.mjs)
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "{{BASE_URL}}",
  apiKey: "YOUR_API_KEY",
});

const reply = await client.chat.completions.create({
  model: "{{MODEL}}",
  messages: [{ role: "user", content: "Hello!" }],
});
console.log(reply.choices[0].message.content);

Not sure your key works? The Test your key page checks it and lists the models you can use — no code needed.

For developers: every request sends the key in the header Authorization: Bearer YOUR_API_KEY. The API is OpenAI-compatible.

Use in apps (no code)

Many chat apps, writing tools and plugins let you add your own AI. If yours has a setting called "OpenAI-compatible", "Custom endpoint" or "OpenAI API", it will work.

  1. Open your app's AI settings. Look for a section like "AI", "Model", "API" or "Connections".
  2. Choose the OpenAI-compatible option. It may be called OpenAI, OpenAI-compatible, Custom or Custom endpoint.
  3. Paste the base URL into the address field:
  4. Paste your API key into the "API key" field. It goes in as-is — no "Bearer" in front.
  5. Pick a model. Type or choose a model ID. The Test your key page shows the ones your key can use.
  6. Save and send a test message. If you get an error, see Errors.

What the fields may be called

What to pasteCommon field names
Base URLBase URL, API base, API base URL, Endpoint, API host, OpenAI base URL, Server URL
API keyAPI key, Secret key, Token, Access key
ModelModel, Model name, Model ID, Deployment

Paste the base URL exactly as shown. It already ends in /v1 — don't add a second one. If an app asks for the full "chat completions URL" instead, use /chat/completions.

Getting 404? Some apps add /v1 themselves — try the address without /v1 at the end.

Code libraries (SDKs)

Use the standard openai code library — you only change the base URL and the key. Install it for your language:

pip install openai
npm install openai

Save Node.js examples as a .mjs file (e.g. hello.mjs) and run node hello.mjs.

Environment variables (recommended)

Keep your key out of your code. The openai library reads these two settings automatically, so OpenAI() needs no arguments:

# These last only for this window
$env:OPENAI_BASE_URL = "{{BASE_URL}}"
$env:OPENAI_API_KEY  = "YOUR_API_KEY"
# These last only for this terminal window
export OPENAI_BASE_URL="{{BASE_URL}}"
export OPENAI_API_KEY="YOUR_API_KEY"
from openai import OpenAI

client = OpenAI()  # reads OPENAI_BASE_URL and OPENAI_API_KEY

reply = client.chat.completions.create(
    model="{{MODEL}}",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(reply.choices[0].message.content)
import OpenAI from "openai";

const client = new OpenAI(); // reads OPENAI_BASE_URL and OPENAI_API_KEY

const reply = await client.chat.completions.create({
  model: "{{MODEL}}",
  messages: [{ role: "user", content: "Hello!" }],
});
console.log(reply.choices[0].message.content);

LangChain (Python)

Python
# pip install langchain-openai
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="{{MODEL}}",
    base_url="{{BASE_URL}}",
    api_key="YOUR_API_KEY",
)
print(llm.invoke("Hello!").content)

Other frameworks and tools work the same way: use their OpenAI connector and set a custom base URL.

Chat completions

This is the main endpoint: you send a conversation, the model sends back its reply.

POST/chat/completions

Request body

FieldTypeWhat it does
modelstring, requiredThe model ID. Get the list from Models.
messagesarray, requiredThe conversation. Each item has a role (system, user or assistant) and content.
streambooleanIf true, the reply arrives in pieces as it is written. See Streaming.
temperaturenumber, 0⁠–⁠2Higher is more creative, lower is more focused. Usually 1 by default.
max_tokensintegerUpper limit on the length of the reply, in tokens (small pieces of text — usage and limits are counted in them).
top_pnumberAnother way to control variety. Change this or temperature, not both.
stopstring or arrayText where the model should stop writing.
toolsarrayFunction / tool definitions, for models that support tool calling.

Which optional fields work depends on the model.

Example

curl {{BASE_URL}}/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "{{MODEL}}",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Explain APIs in one line."}
    ],
    "temperature": 0.7
  }'
from openai import OpenAI

client = OpenAI(base_url="{{BASE_URL}}", api_key="YOUR_API_KEY")

reply = client.chat.completions.create(
    model="{{MODEL}}",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Explain APIs in one line."},
    ],
    temperature=0.7,
)
print(reply.choices[0].message.content)
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "{{BASE_URL}}", apiKey: "YOUR_API_KEY" });

const reply = await client.chat.completions.create({
  model: "{{MODEL}}",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "Explain APIs in one line." },
  ],
  temperature: 0.7,
});
console.log(reply.choices[0].message.content);

Response

The reply text is in choices[0].message.content. usage shows how many tokens were used.

JSON
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "model": "{{MODEL}}",
  "choices": [{
    "index": 0,
    "message": { "role": "assistant", "content": "An API lets programs talk to each other." },
    "finish_reason": "stop"
  }],
  "usage": { "prompt_tokens": 24, "completion_tokens": 9, "total_tokens": 33 }
}

Streaming

Streaming shows the reply word by word as it is written, like in a chat app. Add "stream": true to the request.

For developers: the response is a stream of data: {...} lines (server-sent events) and ends with data: [DONE]. Each piece of text is in choices[0].delta.content.

curl -N {{BASE_URL}}/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "{{MODEL}}",
    "stream": true,
    "messages": [{"role": "user", "content": "Write a short poem."}]
  }'
from openai import OpenAI

client = OpenAI(base_url="{{BASE_URL}}", api_key="YOUR_API_KEY")

stream = client.chat.completions.create(
    model="{{MODEL}}",
    messages=[{"role": "user", "content": "Write a short poem."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "{{BASE_URL}}", apiKey: "YOUR_API_KEY" });

const stream = await client.chat.completions.create({
  model: "{{MODEL}}",
  messages: [{ role: "user", content: "Write a short poem." }],
  stream: true,
});
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || "");
}

Models

Your key can use one or more models. The easiest way to see them is the Test your key page. In code, ask the /models endpoint and use an id as the model in your requests.

GET/models

curl {{BASE_URL}}/models \
  -H "Authorization: Bearer YOUR_API_KEY"
from openai import OpenAI

client = OpenAI(base_url="{{BASE_URL}}", api_key="YOUR_API_KEY")

for model in client.models.list():
    print(model.id)
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "{{BASE_URL}}", apiKey: "YOUR_API_KEY" });

for await (const model of client.models.list()) {
  console.log(model.id);
}
Response
{
  "object": "list",
  "data": [
    { "id": "{{MODEL}}", "object": "model" }
  ]
}

Errors

When something goes wrong, your app may show an error number. Here is what each one means and what to do.

CodeWhat it meansWhat to do
400Something in the request is wrong.Check the model name and the message format. The error message says what's wrong.
401The key is missing or wasn't accepted.Check that you pasted the whole key, with no spaces. Still failing? Ask your seller.
402Your key's allowance has run out.Contact the seller you got access from.
403Your key can't use this.This model or feature isn't included with your key. Ask your seller.
404Not found.Check the base URL (one /v1 only) and the model ID. Some apps add /v1 themselves — try the address without /v1 at the end.
429Too many requests, or a limit was reached.Wait a little and try again, or ask your seller about your limits.
500–504A temporary problem.Wait a few seconds and try again.

For developers: errors come back as JSON, {"error": {"message": "...", "type": "...", "code": "..."}}. For 429, respect the Retry-After header if it is present.

Tips

  • Keep your key secret. Don't share it, post it in screenshots or put it in public code. If it leaks, ask your seller for a new one.
  • Call the API from a server, not from website code that visitors can read.
  • Use streaming for chat screens, so people see text right away.
  • Retry 429 and 5xx errors with a growing wait: 1 s, 2 s, 4 s…
  • Set a timeout of 60 seconds or more; long replies can take time.
  • Use max_tokens to keep replies short when you don't need long ones.