Back to Editor

Kreatyw API

Text generation API powered by N-gram language models

Overview

The Kreatyw API provides a simple REST endpoint for generating text continuations using N-gram language models. The API uses Markov chains trained on source texts to predict and generate coherent text sequences.

Base URL

https://kreatyw.krzak.org

Endpoints

POST /api/predict

Generate text continuation based on a given prompt.

Request Body

Parameter Type Required Description
prompt string Required The starting text to continue from
n integer Optional N-gram size (2-5). Default: 4. Higher values produce more coherent but less creative text.
temperature float Optional Sampling temperature (0.1-2.0). Default: 1.6. Higher values increase randomness.
length integer Optional Number of words to generate (1-500). Default: 5.

Response

Field Type Description
prediction string The generated text continuation

Example Request

curl -X POST http://localhost:8000/api/predict \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Kiedyś tak było",
    "n": 4,
    "temperature": 1.2,
    "length": 20
  }'

Example Response

{
  "prediction": "przezroczyste, że prawie ich dostrzec nie mógł. Słysząc bowiem tyle o jej egzystencji. Zaiste z pogardą arcykapłańskich święceń i źle traktujesz sługi boże."
}

JavaScript Example

const response = await fetch('/api/predict', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    prompt: 'Kiedyś tak było',
    n: 3,
    temperature: 0.8,
    length: 15
  })
});

const data = await response.json();
console.log(data.prediction);

Python Example

import requests

response = requests.post('http://localhost:8000/api/predict',
    json={
        'prompt': 'Kiedyś tak było',
        'n': 4,
        'temperature': 1.0,
        'length': 25
    }
)

result = response.json()
print(result['prediction'])

Model Parameters

N-gram Size (n)

Controls the context window size. Higher values use more context words to predict the next word:

Temperature

Controls the randomness of predictions:

Error Handling

The API returns standard HTTP status codes: