Querying data

HQL is a small pipe language for reading an organization's entities: pick a type, filter it, choose the fields, sort, limit. This guide shows how to discover which types and fields exist, write and run queries, search text, group and count, turn a plain-English question into HQL, and read the results that come back abbreviated. It ends with a recipe for finding something when you do not know where it lives.

Your first query

run_hql runs one HQL statement and returns JSON-safe rows.

curl -X POST "https://api.hilus.ai/Platform/query/hql" \
  -H "Authorization: Bearer $HILUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "hql": "Call | status = '\''completed'\'' AND created_at >= NOW() - INTERVAL '\''7 days'\'' | select id, from_number, created_at | order created_at desc | limit 5"
}'

Response:

{
  "rows": [
    {
      "id": "call_1a2b",
      "from_number": "+15555550143",
      "created_at": "2026-09-25T17:42:03Z"
    },
    {
      "id": "call_3c4d",
      "from_number": "+15555550178",
      "created_at": "2026-09-25T15:10:47Z"
    }
  ],
  "truncated_values": 0,
  "hint": null,
  "warnings": []
}

The shape of a query

Every query reads left to right:

<EntityType> [@ <branch>] | <filters> | select <fields> | order <field> asc|desc | limit N

[!WARNING] Always select the fields you need and always limit. Without select, a query returns every column, large text and binary values included, and a wide type such as Call or Conversation can hit the time limit even at limit 1.

Discover types and fields

HQL uses the same names as the entity model, so start by describing it. With no arguments, describe lists every type with a summary:

curl -X GET "https://api.hilus.ai/Platform/entities/entity-graph" \
  -H "Authorization: Bearer $HILUS_API_KEY"

With names, it returns each type's fields, including their types, allowed values and target_types, the related types you can follow with a dotted path:

curl -X GET "https://api.hilus.ai/Platform/entities/entity-graph?names=%5B%22Call%22%5D&include_tools=false" \
  -H "Authorization: Bearer $HILUS_API_KEY"

When you know what you want but not what it is called, search by intent. Hits name the type and the full field path:

curl -X GET "https://api.hilus.ai/Platform/entities/entity-graph?query=caller+phone+number&names=%5B%22Call%22%5D&limit=5" \
  -H "Authorization: Bearer $HILUS_API_KEY"

For one corner of a large type, form_schema takes a dotted path for one subtree, or a query to search every nested field:

curl -X GET "https://api.hilus.ai/Platform/entities/schema/Conversation?query=who+the+conversation+is+assigned+to&limit=5" \
  -H "Authorization: Bearer $HILUS_API_KEY"

A query that names an unknown field fails with status 400, and the error carries the owning type's full field list (or, for an unknown type, the valid type names), so one failed query tells you how to fix it.

Filter

Filters combine comparisons with AND, OR, NOT and parentheses.

Operators Meaning
= != > >= < <= Comparison
in (...), not in (...) Set membership
is null, is not null Presence
BETWEEN a AND b Range
like, ilike Wildcards % and _ (unindexed)
=~ =~* !~ !~* Regular expressions (unindexed)
~* ~= ~~ Full-text, semantic and hybrid search (indexed)

Nested paths work everywhere: conversation.messages.role = 'tool' follows a call into its conversation and messages. Dates parse in many formats (created_at >= '2026-09-01', '3 days ago', NOW() - INTERVAL '24 hours'; words such as 'yesterday' are not understood), and phone numbers are normalized, so from_number = '5555550143' matches +15555550143. Each kind of value's dtype page says what a filter on it accepts; for moments, how a time without an offset is read.

Pass values as named parameters rather than pasting them into the string:

curl -X POST "https://api.hilus.ai/Platform/query/hql" \
  -H "Authorization: Bearer $HILUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "hql": "Call | from_number = :phone AND direction = '\''inbound'\'' | select id, status, created_at | order created_at desc | limit 10",
  "params": {
    "phone": "+15555550143"
  }
}'

Select only what you need

select takes fields and dotted paths. Braces pick several sub-fields of each item of a nested list, and a slice takes part of a list (messages.content[:3] is the first three):

curl -X POST "https://api.hilus.ai/Platform/query/hql" \
  -H "Authorization: Bearer $HILUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "hql": "Conversation | id = :id | select id, status, messages{role, content}",
  "params": {
    "id": "conv_789"
  }
}'

return_mode controls the row shape. llm_safe (the default) makes every value a JSON scalar and shortens long strings; matches returns raw rows; entity and graph return hydrated entities.

Search text

Pick the operator by what you mean:

curl -X POST "https://api.hilus.ai/Platform/query/hql" \
  -H "Authorization: Bearer $HILUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "hql": "Message | content ~~ '\''prescription refill'\'' AND created_at >= NOW() - INTERVAL '\''30 days'\'' | select id, created_at, content | limit 10",
  "max_chars": 300
}'

ilike '%...%' gives exact substring semantics but scans without an index; content ~* 'Smith' is fast where content ilike '%Smith%' can time out. Use ilike only when you need a true substring and other filters already narrow the rows. When a type has no semantic index in your organization, ~= runs as full text and the response's warnings says so.

Search everything

To find anything your organization stores about a subject without knowing which type holds it, search every type in one query: write * where the type would go, followed by one search. Each row is one entity, ranked by its best-matching passage, and _concrete_type says what kind of entity it is.

curl -X POST "https://api.hilus.ai/Platform/query/hql" \
  -H "Authorization: Bearer $HILUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "hql": "* | ~~ '\''refund policy'\'' | select _concrete_type, id, created_at, match.field, match.text, match.score | limit 10"
}'

Response:

{
  "rows": [
    {
      "_concrete_type": "Document",
      "id": "doc_123",
      "created_at": "2026-08-02T10:14:00Z",
      "match.field": "lines",
      "match.text": "Refunds are issued to the original card within 14 days of a cancellation.",
      "match.score": 0.83
    },
    {
      "_concrete_type": "Message",
      "id": "msg_77",
      "created_at": "2026-11-20T16:05:12Z",
      "match.field": "content",
      "match.text": "Can you tell me what your refund policy is if I cancel?",
      "match.score": 0.71
    },
    {
      "_concrete_type": "Call",
      "id": "call_1a2b",
      "created_at": "2026-11-18T09:31:40Z",
      "match.field": "recording",
      "match.text": "...and the refund policy says you get the deposit back if you cancel a day ahead.",
      "match.score": 0.64
    }
  ],
  "row_count": 3,
  "truncated_values": 0,
  "hint": null,
  "warnings": []
}

match is the best passage: match.field is the field it came from, match.text the passage, match.score how well it matches, match.dtype the kind of value it sits in (string, pdf, image, audio, file and so on), and match.start and match.end where it sits: lines counted from 0 in text and in a PDF's read text, seconds in a recording. match.meta holds the rest, such as the page of a PDF hit. Each dtype's page says what its passages are.

What is searched. Every field that holds text is indexed for search: text and lists of text, text inside nested objects, and stored files, including files attached to the items of a list. The text of scanned PDFs and images (read by OCR) and of recordings (transcribed) is added once that processing finishes in the background, so a file saved a moment ago can match a little later. The search operators are the ones in the "Search text" section: ~~ for a phrase, ~* for exact words and names, ~= for meaning.

Rules for *.

Narrow it by kind of value. A filter on match.dtype in the stage after the search narrows the search itself, so it never crowds out what you asked for. Only hits inside a PDF, with the page each was found on in match.meta (its page, counted from 0):

curl -X POST "https://api.hilus.ai/Platform/query/hql" \
  -H "Authorization: Bearer $HILUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "hql": "* | ~~ '\''refund policy'\'' | match.dtype = '\''pdf'\'' | select _concrete_type, id, match.field, match.text, match.meta | limit 10"
}'

Search one type. To search only one type, name it instead of *: a filter on _concrete_type after a * search only drops rows from the best matches overall, so it can return fewer than the type holds. A search without a field name searches every indexed field of the type, and you can select any of its fields:

curl -X POST "https://api.hilus.ai/Platform/query/hql" \
  -H "Authorization: Bearer $HILUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "hql": "Message | ~~ '\''refund policy'\'' | select id, created_at, role, match.field, match.text | limit 10"
}'

A recording is searched by its transcript, and match.start is the second at which the passage begins, so you can play the moment it was said:

curl -X POST "https://api.hilus.ai/Platform/query/hql" \
  -H "Authorization: Bearer $HILUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "hql": "Call | recording ~~ '\''refund policy'\'' | select id, created_at, from_number, match.text, match.start | limit 10"
}'

Follow a hit to where it belongs. A type held by another type has a field named after the holder, in snake case, even though the model declares the link only on the holder: a message has conversation, for the conversation it belongs to. Select it to get the holder's id, or filter through it:

curl -X POST "https://api.hilus.ai/Platform/query/hql" \
  -H "Authorization: Bearer $HILUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "hql": "Message | id = :id | select id, conversation, conversation.status, conversation.created_at",
  "params": {
    "id": "msg_77"
  }
}'

When the holder links to the type through two fields, such a field would be ambiguous; the error says so and names the query to write from the holder's side instead.

Read a family of types at once. An abstract type, such as Touchpoint for every channel contacts reach the organization through (phone numbers, email addresses, chat and form pages and more), has no records of its own: querying it reads all of its subtypes in one statement, each row with its _concrete_type. Only fields declared on the abstract type can be filtered or selected; to use a subtype's own fields, query the subtype.

curl -X POST "https://api.hilus.ai/Platform/query/hql" \
  -H "Authorization: Bearer $HILUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "hql": "Touchpoint | select _concrete_type, id, created_at | order created_at desc | limit 20"
}'

Group, count and flatten

group by with count(*), sum, avg, min or max aggregates:

curl -X POST "https://api.hilus.ai/Platform/query/hql" \
  -H "Authorization: Bearer $HILUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "hql": "Call | created_at >= NOW() - INTERVAL '\''7 days'\'' | group by status | count(*)"
}'

flatten turns one row per entity into one row per list item, which is how you query inside lists:

curl -X POST "https://api.hilus.ai/Platform/query/hql" \
  -H "Authorization: Bearer $HILUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "hql": "Conversation | id = :id | flatten messages | order by messages.created_at asc | select id, messages.role, messages.content | limit 50",
  "params": {
    "id": "conv_789"
  }
}'

Heavy aggregations over long windows may need more than the default time limit of 5 seconds; raise timeout (up to 60) for those:

curl -X POST "https://api.hilus.ai/Platform/query/hql" \
  -H "Authorization: Bearer $HILUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "hql": "Message | created_at >= NOW() - INTERVAL '\''90 days'\'' | group by role | count(*)",
  "timeout": 30
}'

Ask in plain English

translate_query turns a question into HQL with a model. It does not run the query; read the hql, then run it.

curl -X POST "https://api.hilus.ai/Platform/query/translate" \
  -H "Authorization: Bearer $HILUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "text": "inbound calls from last week that were not answered",
  "entity_type": "Call"
}'

Response:

{
  "entity_type": "Call",
  "hql": "Call | direction = 'inbound' AND status = 'no-answer' AND created_at >= NOW() - INTERVAL '7 days' | select id, from_number, created_at | limit 50",
  "conditions": [
    {
      "path": "direction",
      "op": "=",
      "value": "inbound"
    },
    {
      "path": "status",
      "op": "=",
      "value": "no-answer"
    }
  ],
  "selected_fields": [
    "from_number",
    "created_at"
  ]
}

Pass current_hql with a follow-up ("only the ones from this number") to refine a query instead of starting over. Each translation is one model call. The full language is in the HQL reference; syntax returns the same text:

curl -X GET "https://api.hilus.ai/Platform/query/syntax" \
  -H "Authorization: Bearer $HILUS_API_KEY"

Read large results

In llm_safe mode, a string longer than max_chars (default 200) is cut with a marker that says how many characters are left, and binary values (recordings, PDFs) appear as their content handle with a short excerpt. The response counts what was cut:

Response:

{
  "rows": [
    {
      "id": "msg_77",
      "content": "Hi, I am calling about the invoice from last month. I think the amount is wrong because\u2026[truncated, 812 more chars]"
    }
  ],
  "truncated_values": 1,
  "hint": "1 value(s) truncated due to character limit.",
  "warnings": []
}

Nothing was lost. When the values are only moderately long, rerun with a larger max_chars. For one whole field of one entity, read it with get and paths:

curl -X GET "https://api.hilus.ai/Platform/entities/Message/msg_77?paths=content" \
  -H "Authorization: Bearer $HILUS_API_KEY"

For a value behind a handle (a recording's transcript, a PDF's pages), read the part you need by range or query with get_content; what range counts is on the value's dtype page (pdf pages here):

curl -X POST "https://api.hilus.ai/Platform/dtypes/get-content" \
  -H "Authorization: Bearer $HILUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "ref": "pdf-aB3kQ9",
  "range": [
    1,
    2
  ]
}'

To filter, group, sort or count the rows of a list behind a handle (a report's rows, a long list of results), query the list as a table with run_hql; the next section, "Query a stored value as a table", shows how.

See the reading topic for why large values come back this way.

Query a stored value as a table

When a result came back as a handle (trees and tables hold lists of rows) and you need to filter, group, sort or count the rows of a list inside it, query that list with run_hql. Write handle('<ref>', '<path>') where an entity type would go: path points at the list, and headers names the columns when each row is a list of cells. A search with get_content finds rows that mention a word, but it cannot compare dates or count, and it misses a value on the second line of a cell.

This query reads a report whose rows hold one item per line in some cells. For every contact not yet reached, it returns the earliest due date and everything that is due, for contacts with something due by January 6:

curl -X POST "https://api.hilus.ai/Platform/query/hql" \
  -H "Authorization: Bearer $HILUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "hql": "handle('\''tree-5kR2vQ8m'\'', '\''/result/sections/0/rows'\'', headers='\''/result/sections/0/headers'\'') | explode kind, item, due_date | contact not in :reached | group by contact, phone | min(due_date) as earliest, collect(subject, item, due_date) as items | having earliest <= '\''1/6/2026'\'' | order by earliest asc, contact asc | limit 20",
  "params": {
    "reached": [
      "Ann Lee",
      "Bo Diaz"
    ]
  }
}'

Response:

{
  "rows": [
    {
      "contact": "Cy Ng",
      "phone": "+12065550103",
      "earliest": "2025-12-30",
      "items": [
        {
          "subject": "Max",
          "item": "Annual check",
          "due_date": "2025-12-30"
        },
        {
          "subject": "Max",
          "item": "Follow-up",
          "due_date": "2026-03-12"
        }
      ]
    },
    {
      "contact": "Di Fox",
      "phone": "+12065550104",
      "earliest": "2026-01-02",
      "items": [
        {
          "subject": "Ivy",
          "item": "Annual check",
          "due_date": "2026-01-02"
        }
      ]
    }
  ],
  "truncated_values": 0,
  "hint": null,
  "warnings": [],
  "row_count": 2,
  "total_rows": 2
}

Variations:

curl -X POST "https://api.hilus.ai/Platform/dtypes/get-content" \
  -H "Authorization: Bearer $HILUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "ref": "tree-5kR2vQ8m",
  "path": "/result/sections/0/rows",
  "headers_path": "/result/sections/0/headers",
  "hql": "explode kind, item, due_date | group by contact, phone | min(due_date) as earliest | having earliest <= '\''1/6/2026'\'' | order by earliest asc | limit 20"
}'

These clauses (explode, having, several group or order keys, collect, the functions, contains and startswith) work only on a handle source for now. The full rules, every function and every error message are in the "Handle sources" section of the HQL reference.

Finding something in the data

When you are asked about something ("the call where the caller asked about a refund", "the agent's after-hours message") and do not know where it lives, work outward in this order.

1. Name the type. Search the model by intent with describe and a query. The hits give the type and the field path, for example Message.content or Agent.initial_message:

curl -X GET "https://api.hilus.ai/Platform/entities/entity-graph?query=customer+asked+for+a+refund&limit=5" \
  -H "Authorization: Bearer $HILUS_API_KEY"

To look for the records themselves rather than the field, search every type at once with * in place of the type, as the "Search everything" section shows; each hit names its type and the field that matched.

2. Narrow with HQL. Filter on what you know for sure first (a time window, a phone number, an agent), then search the text, and select only ids and a few fields with run_hql:

curl -X POST "https://api.hilus.ai/Platform/query/hql" \
  -H "Authorization: Bearer $HILUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "hql": "Message | created_at >= NOW() - INTERVAL '\''14 days'\'' AND content ~~ '\''refund'\'' | select id, created_at, content | order created_at desc | limit 20",
  "max_chars": 160
}'

3. Read the one you found in full. Take its id to get (with paths for one field), or its handle to get_content.

4. Check the organization and branch. Nothing found often means you looked in the wrong place: the record may belong to another organization, or the change you are looking for may still be on a feature branch (@ feature/new-hours). See the discovery topic.

5. Loosen, do not guess. Widen the time window, switch ~* to ~~, or drop a filter. A timeout usually means a missing select or an ilike, not that you need a larger timeout.

Errors and time limits

Deleting with HQL

[!WARNING] HQL can also change data. DELETE <Type> | <filter> deletes every match: a filter is required, the delete is soft unless you append | hard (permanent), and @ * reaches every branch. An execute stage runs a tool on every matching entity. Run the same filter as a read first and check the count.

curl -X POST "https://api.hilus.ai/Platform/query/hql" \
  -H "Authorization: Bearer $HILUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "hql": "Call | status = '\''failed'\'' AND created_at < '\''2026-01-01'\'' | count(*)"
}'

Next steps