DocumentationOpenAI compatibility
Get started
OpenAI compatibility
Your code written for OpenAI works with Learnya. Three values change, the rest stays the same.
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
)import OpenAI from "openai"
const client = new OpenAI({
baseURL: "https://api.learnya.ai/v1",
apiKey: process.env.LEARNYA_API_KEY,
})
const response = await client.chat.completions.create({
model: "flash",
messages,
})import OpenAI from "openai"
const client = new OpenAI({
baseURL: "https://api.learnya.ai/v1",
apiKey: process.env.LEARNYA_API_KEY,
})
const response: OpenAI.ChatCompletion =
await client.chat.completions.create({
model: "flash",
messages,
})Supported parameters
The chat endpoint accepts the following OpenAI parameters and passes them to the model.
| Parameters | For |
|---|---|
model, messages | The model and the conversation. The only required fields |
stream, stream_options | Streamed response, with the token count at the end |
max_tokens, stop, n | Length, stop sequences and number of responses |
temperature, top_p, top_k, min_p, seed | Sampling |
presence_penalty, frequency_penalty, logit_bias | Repetition and word choice |
logprobs, top_logprobs | Token probabilities |
tools, tool_choice, parallel_tool_calls | Calling your functions |
response_format | A JSON response |
reasoning_effort | Reasoning effort: none, low, medium or high |
user, metadata | Your own identifiers |
What differs
| Subject | With Learnya |
|---|---|
| Model name | A Learnya model name: flash or max. Any other name returns a 400 error listing the known names. |
| Unknown field | Removed before reaching the model. The x-learnya-dialect response header names what was removed. |
| Response length | max_tokens is capped at the model’s limit if it exceeds it. |
| Streaming | The last message of the stream carries the token count, unless you set stream_options yourself. |
| Reasoning | The model’s reasoning arrives in reasoning_content, alongside the response. |
| Errors | The error body carries a message and a type, without the code and param fields. |
| Model list | The model list is not served to API keys. The names are on the Models page. |
| Browser | No 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.