DocumentationQuickstart
Get started
Quickstart
A key, a request, a response. Five minutes if you already have Python or Node.js.
On this page
Three steps
Get a key
API keys are available to Team workspaces and partners. Write to us, we create the key with you and you receive it once.
Keep it out of your code
Put it in an environment variable on your server. The examples in this documentation read it from there.
export LEARNYA_API_KEY="lya_svc_…"Send the request
With the OpenAI SDK or a plain HTTP request. The values in amber are the ones you change.
curl https://api.learnya.ai/v1/chat/completions \ -H "Authorization: Bearer $LEARNYA_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "flash", "messages": [ { "role": "user", "content": "Summarise Swiss data protection law." } ] }'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=[ { "role": "user", "content": "Summarise Swiss data protection law.", } ], ) print(response.choices[0].message.content)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: [ { role: "user", content: "Summarise Swiss data protection law.", }, ], }) console.log(response.choices[0].message.content)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: [ { role: "user", content: "Summarise Swiss data protection law.", }, ], }) const answer: string | null = response.choices[0].message.content console.log(answer)Response{ "id": "chatcmpl-5d0c9e2a41b7", "object": "chat.completion", "created": 1791633600, "model": "learnya-flash", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "1. Personal data is processed lawfully, in good faith and for a stated purpose.\n2. Data protection is built in by design and by default.\n3. People can access their data and have it corrected or deleted." }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 21, "completion_tokens": 52, "total_tokens": 73 } }
Read the response
The response text is in the first choice, its message, its content. The token count is in the usage field.
| Where | What you find there |
|---|---|
choices[0].message.content | The response text |
choices[0].finish_reason | Why the model stopped: natural end or length limit reached |
usage | The tokens the model read and wrote |
x-learnya-slot | Response header: the Learnya model that answered |