Laya Cloud quickstart
Send a support ticket once, then ask for its department, frustration level, and urgency. The API returns a named, typed answer for each question.
Set up your client
Create an API key and export these two environment variables. Use the service root as the base URL; the SDK adds the versioned path.
export TYPESAFE_BASE_URL=https://YOUR_LAYA_HOST
export TYPESAFE_API_KEY=YOUR_LAYA_API_KEY
The examples below use the same variables and request in every language. Python requires typesafe-sdk==0.7.1; JavaScript requires Node.js 20+ and @typesafe-ai/[email protected].
python3 -m pip install typesafe-sdk==0.7.1
# Or, for a JavaScript project:
npm install @typesafe-ai/[email protected]
Make your first request
POST /v1/systemone evaluates the three questions together. Choose a language, copy the example, and run it after setting your API key.
curl
curl --fail-with-body --silent --show-error "$TYPESAFE_BASE_URL/v1/systemone" \
-H "Authorization: Bearer $TYPESAFE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "jev-latest",
"state": "Hi, I was billed twice for March. Please refund the duplicate.",
"questions": {
"department": {
"type": "choice",
"instructions": "Which team should handle this?",
"criteria": {"billing": "Payment issues", "technical": "Bugs", "sales": "Sales questions"}
},
"frustration": {
"type": "score",
"instructions": "How frustrated is the customer?",
"criteria": ["Calm", "Frustrated but civil", "Very angry"]
},
"is_urgent": {"type": "noul", "instructions": "The message conveys urgency"}
}
}'
Python
from typesafe_sdk import Choice, Noul, Score, TypeSafeClient
# Reads TYPESAFE_BASE_URL and TYPESAFE_API_KEY.
with TypeSafeClient() as client:
result = client.system_one(
model="jev-latest",
state="Hi, I was billed twice for March. Please refund the duplicate.",
questions={
"department": Choice(
instructions="Which team should handle this?",
criteria={"billing": "Payment issues", "technical": "Bugs", "sales": "Sales questions"},
),
"frustration": Score(
instructions="How frustrated is the customer?",
criteria=["Calm", "Frustrated but civil", "Very angry"],
),
"is_urgent": Noul(instructions="The message conveys urgency"),
},
)
print(result.model_dump_json(indent=2))
JavaScript
import { choice, noul, score, TypeSafeClient } from '@typesafe-ai/sdk';
// Reads TYPESAFE_BASE_URL and TYPESAFE_API_KEY.
const client = new TypeSafeClient();
const result = await client.systemOne({
model: 'jev-latest',
state: 'Hi, I was billed twice for March. Please refund the duplicate.',
questions: {
department: choice('Which team should handle this?', {
billing: 'Payment issues', technical: 'Bugs', sales: 'Sales questions',
}),
frustration: score('How frustrated is the customer?', [
'Calm', 'Frustrated but civil', 'Very angry',
]),
is_urgent: noul('The message conveys urgency'),
},
});
console.log(JSON.stringify(result, null, 2));
Read the response
This is an actual response recorded from the local fake-model API, included to demonstrate the wire format, not model quality. The hosted model returns its own probabilities; token counts also depend on the tokenizer.
{
"model": "laya-0.3.5",
"answers": {
"department": {
"type": "choice",
"choice": "technical",
"confidence": 0.4709,
"probabilities": {
"billing": 0.3226,
"technical": 0.4709,
"sales": 0.2065
}
},
"frustration": {
"type": "score",
"score": 1.0,
"confidence": 0.0,
"legend": {
"0": "Calm",
"1": "Frustrated but civil",
"2": "Very angry"
},
"probabilities": {
"0": 0.3333,
"1": 0.3333,
"2": 0.3333
}
},
"is_urgent": {
"type": "noul",
"noul": 0.5515
}
},
"usage": {
"input_tokens": 39,
"output_tokens": 0
}
}
department.choiceis the selected label;probabilitiescontains a probability for every option.frustration.scoreis the probability-weighted level from your ordered criteria. It can fall between levels.is_urgent.noulis the probability that the statement is true. Noul has no separate confidence field.usage.input_tokenscounts the state once plus instructions and criteria.output_tokensis zero.modelidentifies the model that answered, even when you send thejev-latestalias.
Before sending production traffic
Laya currently accepts short English inputs. Longer questions leave less room for the state, and oversized requests are rejected rather than truncated. Review the limits, migration checklist, error reference, and OpenAPI contract. Check Usage after your first successful request.