Lingara Lingara Documentation Guides API Bibliothèques Applications Créer Application web
Langue: Français

Se reconnecter à un plan de leçon

Version de l'API 2026-10-affable-towhee

get https://api.getlingara.com/v1/lesson-plans/{id}/stream

Rejoint le flux de progression d'un plan encore en cours de génération. Un plan terminé répond par un unique result. Un plan encore en cours de génération sans flux actif à rejoindre répond par un unique pending ; interrogez GET /v1/lesson-plans/{id} jusqu'à ce qu'il soit terminé.

Portées lesson_plans:read

Paramètres

Lingara-Versionheaderstringfacultatif
La version de l'API sous laquelle traiter cette requête. Sans elle, un jeton d'accès obtient la version à laquelle son client est rattaché, et une requête sans jeton obtient la version actuelle. La version encore en développement ne s'atteint qu'en la nommant ici. Une version inconnue répond 400 avec le code api_version_unknown. GET /v1/versions liste les versions.
idpathstringobligatoire

Réponses

200 La progression restante du plan, puis le plan

Événements du flux text/event-stream

Envoie un commentaire keepalive toutes les 15 secondes.

started PlanStarted
plan_idstringobligatoire
phase PlanPhase
phasestringobligatoire
attemptintegerobligatoire
result PlanResult Termine le flux
planLessonPlanobligatoire
idstringobligatoire
statusPlanStatusobligatoire
titlestring | nullfacultatif
source_langstringobligatoire
target_langstringobligatoire
levelintegerobligatoire
created_atstringobligatoire
completed_atstring | nullfacultatif
ai_generatedbooleanobligatoire
contentLessonPlanContent | nullfacultatif
introductionstring | nullfacultatif
learning_objectivesarray of stringobligatoire
vocabularyarray of PlanWordobligatoire
wordstringobligatoire
pronunciationstring | nullfacultatif
translationstringobligatoire
setsarray of PlanSetobligatoire
numberintegerobligatoire
contextstring | nullfacultatif
questionsarray of PlanQuestionobligatoire
typestringobligatoire
promptstringobligatoire
optionsarray of string | nullfacultatif
answerstringobligatoire
explanationstringobligatoire
hintstring | nullfacultatif
pending PlanPending Termine le flux
plan_idstringobligatoire
statusPlanStatusobligatoire
error StreamError Termine le flux

Arrive dans la réponse 200. La ligne d'état a déjà été envoyée, donc un échec survenu après l'ouverture du flux est signalé par cet événement.

codestringobligatoire
messagestringobligatoire
plan_idstring | nullfacultatif

Erreurs

410application/json
La version de l'API sous laquelle cette requête est traitée a été retirée. Envoyez une version prise en charge dans Lingara-Version, ou rattachez le client à une autre version.
4XXapplication/json
La requête a été refusée. code indique pourquoi, et error l'explique en toutes lettres.
503application/json · text/plain
Le service est temporairement indisponible ; réessayez après le nombre de secondes indiqué dans Retry-After. Pendant la maintenance, le corps est du texte brut plutôt que l'enveloppe d'erreur.
5XXapplication/json
La requête a été refusée. code indique pourquoi, et error l'explique en toutes lettres.
codestringobligatoire

Pourquoi la requête a été refusée, sous forme de code stable sur lequel brancher votre logique : par exemple insufficient_scope (403), rate_limited (429) et, pour un client facturé à l'usage, spend_cap_reached (402) et metered_billing_inactive (402).

errorstringobligatoire

Exemple

Langage de l'exemple de code

curl

curl -N "https://api.getlingara.com/v1/lesson-plans/$ID/stream" \
  -H "Authorization: Bearer $LINGARA_TOKEN"

TypeScript

for await (const ev of client.streamLessonPlan({ id: planId })) {
  if (ev.event === "result") console.log("ready:", ev.data.plan.title);
  if (ev.event === "pending") console.log("still", ev.data.status, "- try again later");
}

Rust

use lingara::models::StreamLessonPlanEvent;

let mut stream = client.stream_lesson_plan(&plan_id).await?;
while let Some(event) = stream.next().await {
    match event? {
        StreamLessonPlanEvent::Result(result) => println!("ready: {}", result.plan.title.unwrap_or_default()),
        StreamLessonPlanEvent::Pending(pending) => println!("still {:?} - try again later", pending.status),
        _ => {}
    }
}

Go

// Rejoin a plan still generating, with the plan_id from its started event.
s, err := client.StreamLessonPlan(ctx, "3f1c2a9e-5b7d-4e21-9a0c-6d8e4f2b1a37")
if err != nil {
	return err
}
defer s.Close()
for ev, err := range s.Events() {
	if err != nil {
		return err
	}
	switch e := ev.(type) {
	case lingara.StreamLessonPlanEventResult:
		fmt.Println("ready:", e.Data.Plan.ID)
	case lingara.StreamLessonPlanEventPending:
		fmt.Println("still", e.Data.Status, "- rejoin later")
	}
}

Java

import com.getlingara.client.model.StreamLessonPlanEvent;

try (EventStream<StreamLessonPlanEvent> stream = client.streamLessonPlan(planId)) {
  for (StreamLessonPlanEvent event : stream) {
    if (event instanceof StreamLessonPlanEvent.Result result) {
      System.out.println(result.data().getPlan().getTitle());
    } else if (event instanceof StreamLessonPlanEvent.Pending pending) {
      // Still generating elsewhere: ask again later.
      System.out.println("pending: " + pending.data().getStatus());
    }
  }
}

Kotlin

import com.getlingara.kotlin.LingaraClient
import com.getlingara.kotlin.model.StreamLessonPlanEvent

client.streamLessonPlan(planId).use { stream ->
    stream.collect { event ->
        when (event) {
            is StreamLessonPlanEvent.Result -> println(event.data.plan.title)
            // Still generating elsewhere: ask again later.
            is StreamLessonPlanEvent.Pending -> println("pending: ${event.data.status}")
            else -> Unit
        }
    }
}

Ruby

client.stream_lesson_plan(plan_id) do |event|
  case event
  in Lingara::StreamLessonPlanEventResult => result then puts "ready: #{result.data.plan.title}"
  in Lingara::StreamLessonPlanEventPending => pending then puts "still #{pending.data.status}, try again later"
  else nil
  end
end

PHP

use Lingara\Stream\StreamLessonPlanEvent;

foreach ($client->streamLessonPlan($planId) as $event) {
    if ($event instanceof StreamLessonPlanEvent\Result) {
        echo 'ready: ', $event->data->getPlan()->getTitle(), "\n";
    } elseif ($event instanceof StreamLessonPlanEvent\Pending) {
        echo 'still ', $event->data->getStatus()->value, ", try again later\n";
    }
}

Vous préférez une bibliothèque ? Consultez la section Bibliothèques.

Exemple de flux

event: pending
data: {"plan_id":"3f1c2a9e-5b7d-4e21-9a0c-6d8e4f2b1a37","status":"generating"}

En cas de divergence entre une traduction et la référence en anglais, la référence en anglais fait foi.