Quickstart
Make your first LiyaEngine call, then ground it in your own knowledge, see what happened, and protect it. Every step shows the REST API and the JavaScript and Python SDKs.
In this quickstart you make your first call to LiyaEngine and take it one step past "hello world". You will:
- Get an API key and check that it works.
- Create a domain and an intent: a typed call that reads customer feedback and returns structured JSON.
- Run it, keep context across calls, and read what comes back.
- Ground a second intent in your own documents, so it answers from them and cites its sources.
- See the trace of what happened, and start a guardrail policy.
It uses a small, realistic example, summarizing customer feedback, so you finish with a pattern you can reuse rather than a throwaway call. Every request and response below was captured from a real run of these exact steps.
What you need
- A terminal, and
curl. - Optionally Node.js 18 or later, or Python 3.9 or later, if you want to follow the SDK tabs.
- A few cents of model usage. Nothing here costs more than that.
1. Create an account and get your API key
- Sign up at liyaengine.ai/signup and verify your email. You land in the dashboard.
- Open Administration → API Keys. Under Environment keys you will see your workspace's key, shown masked. Copy the full key when it is first created or after you Rotate key: it is only shown in full once.
- Store it where your code can read it, and never in code that runs in a browser.
The environment key has full access: it can create and change everything, which is what you need for this quickstart. For your product, create a narrower service key under Administration → API Keys → Service keys → Create service key. A runtime key can run things but cannot change anything, which is the right key to put on a server that serves your customers. See Authentication for all four scopes.
2. Check that your key works
Ask for your domains. A new workspace has none, so an empty list is the right answer.
curl -s "$LIYA_API_URL/v1/domains" -H "Authorization: Bearer $LIYA_API_KEY"A working key answers 200 with { "success": true, "data": { "domains": [ ... ] } }. A key that is missing or wrong answers 401, and the code tells you which:
| Code | Meaning |
|---|---|
MISSING_API_KEY | There is no Authorization header. |
INVALID_API_KEY_FORMAT | The key does not start with liya_, or is too short. Check for a stray quote or newline. |
INVALID_API_KEY | The key looks right but is not one of yours, or was revoked or rotated. |
The SDK snippets below reuse client.
3. Create a domain
A domain is the container for one area of work. It carries the instructions every call inherits, and later the knowledge and guardrail policy that belong to it. Ours reads customer feedback.
Open Build → Domains and choose New domain. Name it Quickstart, so its key is quickstart, and under Operating instructions paste:
You read short pieces of customer feedback for a software company. Be accurate and brief.
4. Create an intent
An intent is one named, typed capability: a prompt, an input contract, and an output contract. Callers send fields and get back JSON in a shape you defined, checked against your schema before you see it. That is what makes a model call safe to put behind application code.
Open Build → Intents and add an intent to Quickstart. Set the key to summarize_feedback, write the one-sentence description, and paste the prompt from the API tab: its {{feedback}} placeholder becomes an input field. Under Contract, define the output fields to match the schema, then save.
The {{feedback}} placeholder is filled from the call's input. The schemas are the contract: sentiment can only be one of three values, and topics has at most three entries.
5. Run it
Every call names a domain, an intent and an input. input.user_id is required: any string from your own system that identifies the end user. It keeps conversations apart and attributes usage, and a call without it is rejected.
curl -s -X POST "$LIYA_API_URL/v1/run" \
-H "Authorization: Bearer $LIYA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"domain": "quickstart",
"intent": "summarize_feedback",
"input": {
"user_id": "user_001",
"feedback": "I love the new dashboard, but exporting a report takes forever and sometimes times out."
}
}'The response, trimmed to what you will use:
{
"success": true,
"data": {
"response": {
"structured": {
"sentiment": "neutral",
"summary": "The customer loves the new dashboard but finds report exports very slow and prone to timing out.",
"topics": ["dashboard", "report export performance", "timeouts"]
},
"confidence": 0.5,
"sources": [],
"metadata": { "guardrails_passed": true, "grounding_verified": false, "flags": ["no_context_retrieved"] }
},
"session": { "id": "cmx2sbu810013121v1gdtefix", "turns": 1, "memory_updated": false }
},
"metadata": {
"intent": "summarize_feedback",
"domain": "quickstart",
"model_used": "claude-fable-5-1",
"cost_usd": 0.00663,
"latency_ms": 1794
}
}Read the response from the top:
structuredis your output, already checked against the schema. This is the field your application reads. (contentcarries the same answer as text.)confidenceand theflagstell you how well supported the answer is. Hereconfidenceis 0.5 and the flag isno_context_retrieved: the intent has no knowledge to draw on yet, so nothing grounds the answer. That is expected for a summarizer, and step 7 changes it.sessionis the conversation this call belongs to.metadatareports the model, cost and latency.model_usedshows whichever model your workspace is set to use.
6. Keep context with a session
Pass the session.id back as session_id, a top-level field on the request, to continue the same conversation. session.turns counts the calls so far.
curl -s -X POST "$LIYA_API_URL/v1/run" \
-H "Authorization: Bearer $LIYA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"domain": "quickstart",
"intent": "summarize_feedback",
"session_id": "cmx2sbu810013121v1gdtefix",
"input": {
"user_id": "user_001",
"feedback": "Support answered in five minutes and fixed my billing problem. Great service."
}
}'{
"structured": {
"sentiment": "positive",
"summary": "The customer praises support for responding within five minutes and resolving their billing problem.",
"topics": ["support response time", "billing issue resolution", "customer service quality"]
},
"session": { "id": "cmx2sbu810013121v1gdtefix", "turns": 2 }
}How sessions work, and what is kept between conversations, is in Sessions and memory and Memory.
7. Ground it in your own knowledge
So far the model answered from the input alone. Most products need answers that come from your documents, with the source named. You do that with knowledge: documents are split into passages, indexed, and retrieved when a call needs them.
Create a small help document. It uses an invented product, Brightly, so you can see retrieval at work:
# Exporting reports from Brightly
Brightly reports with up to 10,000 rows download straight away. Larger Brightly reports are exported in the background, and we email you a download link within 10 minutes.
If a Brightly export times out, narrow the date range or add a filter and try again. Brightly deletes exports after 7 days, so download yours within a week.Documents live in collections. Create one for the quickstart domain, upload the file into it, and add an intent that answers from it.
- Open Knowledge → Collections, choose New collection, name it Quickstart help, and under Domains that draw from this collection choose Quickstart.
- Open Knowledge → Documents, upload
export-help.md, and choose the collection. - Open Knowledge → Retrieval and ask "Why does my Brightly report export keep timing out?" to see the passages that come back, with their scores.
- Add an intent
answer_questionto Quickstart as in the API tab, and under Grounding and guardrails choose Quickstart help.
Now ask it something the document answers:
curl -s -X POST "$LIYA_API_URL/v1/run" \
-H "Authorization: Bearer $LIYA_API_KEY" -H "Content-Type: application/json" \
-d '{
"domain": "quickstart",
"intent": "answer_question",
"input": { "user_id": "user_001", "question": "Why does my Brightly report export keep timing out?" }
}'{
"content": "The help docs don't say exactly why an export times out, but they do suggest it's related to report size. Reports up to 10,000 rows download immediately, while larger ones are exported in the background with a download link emailed within 10 minutes.\n\nIf your export is timing out, the docs recommend narrowing the date range or adding a filter to reduce the report size, then trying again. Also note that exports are deleted after 7 days, so download yours within a week.",
"confidence": 0.75,
"sources": [
{ "doc": "export-help.md", "relevance": 0.70 },
{ "doc": "export-help.md", "relevance": 0.68 }
],
"metadata": { "guardrails_passed": true, "grounding_verified": true, "flags": [] }
}Compare it with step 5. The answer comes from your document and says so honestly where the document is silent. sources names the passages it was built from, with a relevance score. grounding_verified is now true and flags is empty.
Three things worth knowing:
source_typeslimits what an intent may search. An intent with none, likesummarize_feedback, searches every collection attached to its domain, so it would now see this document too. Name the collections you want, as here.- Retrieval has a similarity floor. A passage must score at least 0.15 to be used, so a question your documents cannot answer finds nothing instead of something unrelated. Tune it with
similarity_thresholdandtop_kinretrieval_config. - A wrong answer can be reported with
POST /v1/corrections, so the passage behind it can be reviewed.
8. See what happened
Every call is recorded automatically, with no instrumentation. In the dashboard, open Observe → Traces and choose the newest one. It shows the input, the retrieved passages with their scores, the model used, the cost and latency, and any guardrail flag. Observe → Costs shows spend by model and by capability.
The same traces are available to your code with a read or full key: GET /v1/traces lists them and GET /v1/traces/{id} opens one. See Traces and the Traces API.
9. Start a guardrail policy
A guardrail policy checks every call before the model sees it and after it answers: personal data, injected instructions, and unsupported answers. A template is a ready-made set of settings for one industry and audience, and previewing one saves nothing.
curl -s -X POST "$LIYA_API_URL/v1/guardrail-templates/general-customer/preview" \
-H "Authorization: Bearer $LIYA_API_KEY" -H "Content-Type: application/json" \
-d '{"config": {}}' | jq '.data.preview.changes'[
{ "id": "injection_mode", "label": "How injection is judged", "from": "Standard", "to": "Balanced" },
{ "id": "ml_unavailable", "label": "If the checking service is down", "from": "Allow", "to": "Flag" },
{ "id": "scan_input_fields", "label": "Scan every input field", "from": "Off", "to": "On" },
{ "id": "harden_prompt", "label": "Treat values as data", "from": "Off", "to": "On" }
]That is what General · customer facing would change from the defaults: it judges injected instructions by how they are used, checks every input field and not just the message, and tells the model to treat values as data. Create a policy from .data.preview.config and attach it to the domain to apply it. The card disputes tutorial walks through that, and shows an injection attempt being refused before any model runs.
When something goes wrong
| You see | Status | What it means |
|---|---|---|
MISSING_API_KEY, INVALID_API_KEY_FORMAT, INVALID_API_KEY | 401 | The key is missing, malformed, or not one of yours. See step 2. |
API_KEY_SCOPE_DENIED | 403 | The key's scope does not allow this. A runtime key cannot create things; use the full key. |
INVALID_INPUT: Missing required field: input.user_id | 400 | Every call needs input.user_id. |
VALIDATION_ERROR: (root) must have required property 'feedback' | 400 | The input does not match the intent's inputSchema. |
INTENT_NOT_FOUND | 404 | There is no active intent with that key in that domain. It is usually a typo: GET /v1/domains and GET /v1/domains/{key}/intents list what exists. |
| "I couldn't find this in the approved sources" | 200 | The guardrail policy's Knowledge grounding is set to Block, and nothing was retrieved. Attach knowledge to the intent, or use a policy that flags instead of blocks. |
DOMAIN_LIMIT_REACHED | 403 | Your plan's domain limit is reached. See Plans and limits. |
Where to go next
| You want to | Go to |
|---|---|
| Build something whole, start to finish | Triage card disputes or a health plan member assistant |
| Have a conversation that remembers and can use tools | Agent orchestration and Memory |
| Automate steps, approvals and apps | Workflow builder, Actions and Integrations |
| Prove it works before you ship | Evaluation Studio and the Evaluation API |
| Version and publish prompts | Prompt Studio |
| Find what keeps going wrong | Self-healing |
| Use LiyaEngine from your assistant or IDE | MCP |
| Understand the whole path of a call | How It Works |
| Look up an endpoint | Reference |