Tutorial · Developers

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

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

Your turn

Try it now.