DocumentationQuickstart

Get started

Quickstart

A key, a request, a response. Five minutes if you already have Python or Node.js.

On this page
  1. Three steps
  2. Read the response
  3. Next steps

Three steps

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

  2. Keep it out of your code

    Put it in an environment variable on your server. The examples in this documentation read it from there.

    Shell
    export LEARNYA_API_KEY="lya_svc_…"
  3. 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."
          }
        ]
      }'
    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.

WhereWhat you find there
choices[0].message.contentThe response text
choices[0].finish_reasonWhy the model stopped: natural end or length limit reached
usageThe tokens the model read and wrote
x-learnya-slotResponse header: the Learnya model that answered

Next steps