DocumentationOpenAI compatibility

Get started

OpenAI compatibility

Your code written for OpenAI works with Learnya. Three values change, the rest stays the same.

On this page
  1. Three values to change
  2. Supported parameters
  3. What differs
  4. Tools that already speak OpenAI

Three values to change

The API URL, the key and the model name. They are in amber.

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.learnya.ai/v1",
    api_key=os.environ["LEARNYA_API_KEY"],
)
response = client.chat.completions.create(
    model="flash", messages=messages
)

Supported parameters

The chat endpoint accepts the following OpenAI parameters and passes them to the model.

ParametersFor
model, messagesThe model and the conversation. The only required fields
stream, stream_optionsStreamed response, with the token count at the end
max_tokens, stop, nLength, stop sequences and number of responses
temperature, top_p, top_k, min_p, seedSampling
presence_penalty, frequency_penalty, logit_biasRepetition and word choice
logprobs, top_logprobsToken probabilities
tools, tool_choice, parallel_tool_callsCalling your functions
response_formatA JSON response
reasoning_effortReasoning effort: none, low, medium or high
user, metadataYour own identifiers

What differs

SubjectWith Learnya
Model nameA Learnya model name: flash or max. Any other name returns a 400 error listing the known names.
Unknown fieldRemoved before reaching the model. The x-learnya-dialect response header names what was removed.
Response lengthmax_tokens is capped at the model’s limit if it exceeds it.
StreamingThe last message of the stream carries the token count, unless you set stream_options yourself.
ReasoningThe model’s reasoning arrives in reasoning_content, alongside the response.
ErrorsThe error body carries a message and a type, without the code and param fields.
Model listThe model list is not served to API keys. The names are on the Models page.
BrowserNo calls from a web page. Call the API from your server.

Tools that already speak OpenAI

Any library that accepts a custom OpenAI API URL works the same way: set https://api.learnya.ai/v1, your key and a Learnya model name.