Lingara Lingara Docs Guides API Libraries Apps Build Web app
Language: English

Send a tutor turn

API version 2026-10-affable-towhee

post https://api.getlingara.com/v1/tutor/message

Sends one message to the tutor and streams the reply as delta events, ending with done. Nothing is stored: send the recent conversation in history, up to 20 entries. character and situation set the scene. Requires a paid plan.

Scopes tutor:converse

Parameters

Lingara-Versionheaderstringoptional
The API version to answer this request under. Without it, an access token gets the version its client is pinned to, and a request with no token gets the current version. The version still in development is reached only by naming it here. An unknown version answers 400 with code api_version_unknown. GET /v1/versions lists the versions.

Request body application/json

messagestringrequired
historyarray of TurnEntryoptional
roleTurnRolerequired
contentstringrequired
source_langstringrequired
target_langstringrequired
levelinteger | nulloptional
characterstring | nulloptional
situationstring | nulloptional

Responses

200 The tutor's reply, piece by piece

Stream events text/event-stream

Sends no keepalive comments.

delta TurnDelta
textstringrequired
notice Notice
codestringrequired
messagestringrequired
done Done Ends the stream
error StreamError Ends the stream

Arrives inside the 200 response. The status line has already been sent, so a failure after the stream opens is reported as this event.

codestringrequired
messagestringrequired
plan_idstring | nulloptional

Errors

402application/json
A metered client's call was refused before it spent anything. spend_cap_reached: the client or its account has reached its monthly spending limit; raise the limit on the Integrations page. metered_billing_inactive: usage billing is not active for this account; set it up, or update the payment method, on the Integrations page.
410application/json
The API version this request is answered under has been discontinued. Send a supported version in Lingara-Version, or re-pin the client.
4XXapplication/json
The request was refused. code says why, and error says it in words.
503application/json · text/plain
The service is temporarily unavailable; retry after the number of seconds in Retry-After. During maintenance the body is plain text rather than the error envelope.
5XXapplication/json
The request was refused. code says why, and error says it in words.
codestringrequired

Why the request was refused, as a stable code to branch on: for example insufficient_scope (403), rate_limited (429) and, for a metered client, spend_cap_reached (402) and metered_billing_inactive (402).

errorstringrequired

Example

Code sample language

curl

curl -N -X POST "https://api.getlingara.com/v1/tutor/message" \
  -H "Authorization: Bearer $LINGARA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"message":"我要两斤荔枝。","history":[{"role":"assistant","content":"欢迎!今天的荔枝很新鲜。"}],"source_lang":"en","target_lang":"zh","level":2,"character":"a fruit seller in a night market","situation":"buying lychees, haggling"}'

TypeScript

const reply = client.sendTutorMessage({
  message: "你好!我想点一杯茶。",
  history: [],
  source_lang: "en",
  target_lang: "zh",
});
for await (const ev of reply) {
  if (ev.event === "delta") process.stdout.write(ev.data.text);
}

Rust

use lingara::models::{SendTutorMessageEvent, TutorTurnRequest};

let request = TutorTurnRequest {
    message: "你好!我想点一杯茶。".into(),
    history: Vec::new(),
    source_lang: "en".into(),
    target_lang: "zh".into(),
    level: None,
    character: None,
    situation: None,
};
let mut reply = client.send_tutor_message(&request).await?;
while let Some(event) = reply.next().await {
    if let SendTutorMessageEvent::Delta(delta) = event? {
        print!("{}", delta.text);
    }
}

Go

s, err := client.SendTutorMessage(ctx, lingara.TutorTurnRequest{
	Message:    "你好!我想点一杯茶。",
	SourceLang: "en",
	TargetLang: "zh",
})
if err != nil {
	return err
}
defer s.Close()
for ev, err := range s.Events() {
	if err != nil {
		return err
	}
	if delta, ok := ev.(lingara.SendTutorMessageEventDelta); ok {
		fmt.Print(delta.Data.Text)
	}
}

Java

import com.getlingara.client.model.SendTutorMessageEvent;
import com.getlingara.client.model.TutorTurnRequest;

TutorTurnRequest turn =
    new TutorTurnRequest().message("荔枝多少钱?").sourceLang("en").targetLang("zh").level(2);
try (EventStream<SendTutorMessageEvent> stream = client.sendTutorMessage(turn)) {
  for (SendTutorMessageEvent event : stream) {
    if (event instanceof SendTutorMessageEvent.Delta delta) {
      System.out.print(delta.data().getText());
    } else if (event instanceof SendTutorMessageEvent.Notice notice) {
      System.out.println("\n(" + notice.data().getMessage() + ")");
    }
  }
}

Kotlin

import com.getlingara.kotlin.LingaraClient
import com.getlingara.kotlin.model.SendTutorMessageEvent
import com.getlingara.kotlin.model.TutorTurnRequest

val turn = TutorTurnRequest(message = "荔枝多少钱?", sourceLang = "en", targetLang = "zh", level = 2)
client.sendTutorMessage(turn).use { stream ->
    stream.collect { event ->
        when (event) {
            is SendTutorMessageEvent.Delta -> print(event.data.text)
            is SendTutorMessageEvent.Notice -> println("\n(${event.data.message})")
        }
    }
}

Ruby

history = [{role: "user", content: "你好"}, {role: "assistant", content: "你好!你想练习什么?"}]
client.send_tutor_message(message: "我想点菜", history: history, source_lang: "en", target_lang: "zh") do |event|
  case event
  in Lingara::SendTutorMessageEventDelta => delta then print delta.data.text
  in Lingara::SendTutorMessageEventNotice => notice then warn notice.data.message
  else nil
  end
end
puts

PHP

use Lingara\Model\TutorTurnRequest;
use Lingara\Stream\SendTutorMessageEvent;

$turn = new TutorTurnRequest(['message' => '荔枝多少钱?', 'source_lang' => 'en', 'target_lang' => 'zh', 'level' => 2]);
foreach ($client->sendTutorMessage($turn) as $event) {
    if ($event instanceof SendTutorMessageEvent\Delta) {
        echo $event->data->getText();
    } elseif ($event instanceof SendTutorMessageEvent\Notice) {
        echo "\n(", $event->data->getMessage(), ')';
    }
}
echo "\n";

Prefer a library? See the Libraries section.

Example stream

event: delta
data: {"text":"两斤荔枝,"}

event: delta
data: {"text":"一共三十块。"}

event: done
data: {}