Completions API

The completions endpoint allows you to generate text completions using KrosAI’s language models. This is ideal for tasks like content generation, translation, and text transformation.

Request Body

prompt string required

The prompt to generate completions for


model string required

The ID of the model to use. Currently supported: KrosMLingual1.0.1


max_tokens integer default:"100"

The maximum number of tokens to generate


temperature number default:"0.7"

Controls randomness in the output. Values between 0 and 1. Higher values mean more random completions.


top_p number default:"1"

Controls diversity via nucleus sampling. Values between 0 and 1.


Example Request

Example Request
{ 
"prompt": "Translate to Yoruba: Hello, how are you?", 
"model": "KrosMLingual1.0.1", 
"max_tokens": 50, 
"temperature": 0.7 
}

Example Response

Example Response
{
  "id": "cmpl-123abc",
  "object": "text_completion",
  "created": 1677649420,
  "model": "KrosMLingual1.0.1",
  "choices": [{
    "text": "Bawo ni, se daadaa ni?",
    "index": 0,
    "finish_reason": "stop"
  }],
  "usage": {
    "prompt_tokens": 8,
    "completion_tokens": 6,
    "total_tokens": 14
  }
}

All requests must include an API key in the Authorization header.

Error Responses

400: Bad Request object

Invalid request parameters


401: Unauthorized object

Invalid or missing API key


429: Too Many Requests object

Rate limit exceeded

Best Practices

  1. System Messages: Use system messages to set the behavior and context for your assistant.

  2. Message History: Keep message history concise to stay within token limits.

  3. Temperature: Use a lower temperature (0.2-0.4) for more focused, deterministic responses.

  4. Rate Limits: Implement proper error handling for rate limits

Last updated