DokumentationSchnellstart
Loslegen
Schnellstart
Ein Schlüssel, eine Anfrage, eine Antwort. Fünf Minuten, wenn Sie Python oder Node.js bereits installiert haben.
Auf dieser Seite
Drei Schritte
Einen Schlüssel erhalten
API-Schlüssel stehen Team-Arbeitsbereichen und Partnern offen. Schreiben Sie uns, wir erstellen den Schlüssel mit Ihnen, und Sie erhalten ihn ein einziges Mal.
Den Schlüssel aus dem Code heraushalten
Legen Sie ihn in einer Umgebungsvariable Ihres Servers ab. Die Beispiele dieser Dokumentation lesen ihn dort.
export LEARNYA_API_KEY="lya_svc_…"Anfrage senden
Mit dem OpenAI SDK oder einer einfachen HTTP-Anfrage. Die bernsteinfarbenen Werte passen Sie an.
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)Antwort{ "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 } }
Die Antwort lesen
Der Antworttext steht im ersten Element von choices, in dessen message und dort in content. Die Token-Zählung steht im Feld usage.
| Wo | Was Sie dort finden |
|---|---|
choices[0].message.content | Der Text der Antwort |
choices[0].finish_reason | Warum das Modell aufgehört hat: natürliches Ende oder Längenlimit erreicht |
usage | Die vom Modell gelesenen und geschriebenen Tokens |
x-learnya-slot | Antwort-Header: das Learnya-Modell, das geantwortet hat |