Call the API with the OpenAI SDK
Connect an existing application to the Learnya API by changing only the address and the key of the OpenAI client.
10 min · 6 steps · for everyone
- Step 1
Create a key
From your account, on the Dev or Team plan, create an API key. Limit its scopes to what is strictly needed, set a quota and, if your server has a fixed address, add it to the list of allowed IPs.
- Step 2
Install the SDK
Install the official OpenAI library in your project, for example with pip install openai in Python. Store the key in an environment variable, never in the code.
- Step 3
Point the client to Learnya
Create the client with base_url="https://api.learnya.ai/v1" and your Learnya key. The rest of your code stays the same, since the API is OpenAI-compatible.
- Step 4
Make a first call
Call client.chat.completions.create(model="flash", messages=[{"role": "user", "content": "Summarise this text in three points."}]). Use the "max" model for tasks that need long reasoning.
- Step 5
Add embeddings and images
The same SDK calls work for embeddings and image generation. The data stays in Switzerland and is never used to train the models.
- Step 6
Handle quotas and limits
Build in a retry with a delay when the API returns 429, which means the rate limit has been reached. Track each key’s usage from your account.