Skip to main content

Internal Runtime API References

Introduction

Primitive Value Types

Low-level API requests in Ailoy are made using a JSON-like object as the input argument. The key difference from standard JSON is that binary values can also be included.

In Ailoy, you do not need to manually construct this object. Default types in Python and JavaScript are automatically converted into the appropriate internal representation when a request is sent.

The table below summarizes how types in Python and JavaScript are mapped:

NamePythonJavascript
nullNoneundefined, null
boolboolboolean
uintintnumber
intintnumber
floatfloatnumber
doublefloatnumber
stringstrstring
arrayListArray
mapDictobject
ndarraynumpy.ndarrayTypedArray

Iterative output

In Ailoy, function outputs are designed to be iterable by default. A function may produce output either as a single response or as a sequence of multiple packets. The runtime continues to emit packets until it encounters a packet with the field finish: true. If the function completes in one response, that single packet will include finish: true. If the function produces multiple outputs, each packet will be yielded in order, and only the final one will have finish: true.

In this documentation, the flag iterative: true indicates that the function may return multiple output packets. When using such a function, users must consume the output using an iterator loop (e.g., for or async for) to ensure all packets are handled. On the other hand, if iterative is set to false, the function is guaranteed to produce its entire output in a single packet. In this case, it is safe to call the function as a regular method and consume the result directly, without iteration.


calculator

  • Type: Function
  • Module: default

A simple calculator function.

Parameters

NameTypeDescriptionRequired
expressionstringexpression to be calculated

Outputs

NameTypeDescription
valuedoublecalculation result

iterative: false

http_request

  • Type: Function
  • Module: default

Sends an HTTP(S) request to the specified URL and returns the response.

Parameters

NameTypeDescriptionRequired
urlstringbase url to request
methodstringrequest method among GET, POST, PUT, DELETE
headersmaprequest headers
bodystringrequest body

Outputs

NameTypeDescription
status_codeuintHTTP status code
headersmapresponse headers
bodybytesresponse body

iterative: false


chromadb_vector_store

  • Type: Component
  • Module: language

A vector store backed by ChromaDB as the underlying storage and retrieval engine.

Parameters

NameTypeDescriptionRequired
urlstringURL of the chromadb server
collectionstringCollection name to use (defaults to default_collection)

clear

  • Type: Method
  • Component: chromadb_vector_store

Clears all items from the vector store.

Parameters

None

Outputs

None

iterative: false

get_by_id

  • Type: Method
  • Component: chromadb_vector_store

Retrieves a stored item by its unique identifier, returning the embedding, document, and metadata.

Parameters

NameTypeDescriptionRequired
idstringUnique identifier of item to find

Outputs

NameTypeDescription
idstringUnique identifier of the found item
embeddingndarrayEmbedding of the found item
documentstringDocument of the found item
metadatamapMetadata of the found item

iterative: false

insert

  • Type: Method
  • Component: chromadb_vector_store

Inserts a single embedding into the vector store along with its associated document and optional metadata.

Parameters

NameTypeDescriptionRequired
embeddingndarrayembedding to insert
documentstringoriginal document corresponding to embedding
metadatamap or nullarbitrary key-value pairs with JSON-serializable (defaults to null)

Outputs

NameTypeDescription
idstringUnique identifier of the added item

insert_many

Inserts multiple embeddings into the vector store in a batch. Each item must follow the same format as in insert.

  • Type: Method
  • Component: chromadb_vector_store

Parameters

Array of objects(map) with insert inputs

Outputs

NameTypeDescription
idsarray<string>Unique identifiers of the added items (same order with items)

iterative: false

remove

  • Type: Method
  • Component: chromadb_vector_store

Removes a stored item from the vector store by its unique identifier.

Parameters

NameTypeDescriptionRequired
idstringUnique identifier of item to remove

Outputs

None

iterative: false

retrieve

  • Type: Method
  • Component: chromadb_vector_store

Searches for the most similar items to the given query embedding. Returns the top-k results along with similarity scores.

Parameters

NameTypeDescriptionRequired
query_embeddingstringEmbedding for query message
top_kuintNumber of results to retrieve at most

Outputs

NameTypeDescription
resultsarray<map>Retrieved results where each item consists of
id(string): Unique identifier of the item
document(string): Document of the item
metadata(map or null): Metadata of the item
similarity(float): cosine similarity between query embedding

iterative: false

download_model

  • Type: Function
  • Module: language

Download the model specified by model ID and additional attributes.

Parameters

NameTypeDescriptionRequired
model_idstringModel ID
quantizationstringQuantization method
Available values: q4f16_1
devicestringTarget device
Available values: metal, vulkan

Outputs

NameTypeDescription
model_pathstringPath to the downloaded model

faiss_vector_store

  • Type: Component
  • Module: language

A vector store component using Faiss as the provider.

Parameters

NameTypeDescriptionRequired
dimensionuintDimension of the index

clear

  • Type: Method
  • Component: faiss_vector_store

Clears all items from the vector store.

Parameters

None

Outputs

None

iterative: false

get_by_id

  • Type: Method
  • Component: faiss_vector_store

Retrieves a stored item by its unique identifier, returning the embedding, document, and metadata.

Parameters

NameTypeDescriptionRequired
idstringUnique identifier of item to find

Outputs

NameTypeDescription
idstringUnique identifier of the found item
embeddingndarrayEmbedding of the found item
documentstringDocument of the found item
metadatamapMetadata of the found item

iterative: false

insert

  • Type: Method
  • Component: faiss_vector_store

Inserts a single embedding into the vector store along with its associated document and optional metadata.

Parameters

NameTypeDescriptionRequired
embeddingndarrayembedding to insert
documentstringoriginal document corresponding to embedding
metadatamap or nullarbitrary key-value pairs with JSON-serializable (defaults to null)

Outputs

NameTypeDescription
idstringUnique identifier of the added item

iterative: false

insert_many

  • Type: Method
  • Component: faiss_vector_store

Inserts multiple embeddings into the vector store in a batch. Each item must follow the same format as in insert.

Parameters

Array of objects(map) with insert inputs

Outputs

NameTypeDescription
idsarray<string>Unique identifiers of the added items (same order with items)

iterative: false

remove

Removes a stored item from the vector store by its unique identifier.

  • Type: Method
  • Component: faiss_vector_store

Parameters

NameTypeDescriptionRequired
idstringUnique identifier of item to remove

Outputs

None

iterative: false

retrieve

  • Type: Method
  • Component: faiss_vector_store

Searches for the most similar items to the given query embedding. Returns the top-k results along with similarity scores.

Parameters

NameTypeDescriptionRequired
query_embeddingstringEmbedding for query message
top_kuintNumber of results to retrieve at most

Outputs

NameTypeDescription
resultsarray<map>Retrieved results where each item consists of
id(string): Unique identifier of the item
document(string): Document of the item
metadata(map or null): Metadata of the item
similarity(float): cosine similarity between query embedding

iterative: false

list_local_models

  • Type: Function
  • Module: language

Lists downloaded models in local cache directory.

Parameters

None

Outputs

NameTypeDescription
resultsarray<map>Result items where each item consists of the following schema
NameTypeDescription
typestringModel Type
Available values: tvm
model_idstringModel ID
attributesmapModel Attributes, including quantization and device for tvm type models
model_pathstringPath to the model
total_bytesuintSum of model's file size in bytes

openai

  • Type: Component
  • Module: language

A tvm_language_model compatible using the OpenAI API, an LLM component.

Parameters

NameTypeDescriptionRequired
api_keystringAPI key to use on inference
modelstringModel name
Available values: gpt-4o (defaults to gpt-4o)

infer

  • Type: Method
  • Component: openai

Performs inference, generates outputs.

Parameters

NameTypeDescriptionRequired
messagesarray<map>array of messages (OpenAI API compatible)
toolsarray<map>tools to be used (defaults to empty string)

Outputs

NameTypeDescription
messagemapresult message
finish_reasonstringfinished reason.
Available values: stop, tool_call, length, error

iterative: false

remove_model

  • Type: Function
  • Module: language

Remove the model specified by model ID.

Parameters

NameTypeDescriptionRequired
model_idstringModel ID

Outputs

NameTypeDescription
skippedboolWhether the deletion is skipped
model_pathstringPath to the removed model

split_text

  • Type: Function
  • Module: language
  • Ailas: split_text_separators_recursively

Parameters

NameTypeDescriptionRequired
textstringText to split
chunk_sizeuintChunk size to split (defaults to 4000)
chunk_overlapuintChunk overlap size (defaults to 200)
separatorsarray<string>Separators to use (defaults to ["\n\n", "\n", " ", ""])
length_functionstringLength function to use
Available values: default, string (defaults to default)

Outputs

NameTypeDescription
chunksarray<string>Text chunks

iterative: false

split_text_by_separator

  • Type: Function
  • Module: language

Parameters

NameTypeDescriptionRequired
textstringText to split
chunk_sizeuintChunk size to split (defaults to 4000)
chunk_overlapuintChunk overlap size (defaults to 200)
separatorstringSeparator to use (defaults to \n\n)
length_functionstringLength function to use
Available values: default, string (defaults to default)

Outputs

NameTypeDescription
chunksarray<string>Text chunks

iterative: false

tvm_embedding_model

  • Type: Component
  • Module: language

Defines an on-device embedding model using TVM as the provider.

Parameters

NameTypeDescriptionRequired
modelstringModel name to use.
Available values: BAAI/bge-m3 (defaults to BAAI/bge-m3)
quantizationstringQuantization method.
Available values: q4f16_1 (defaults to q4f16_1)

infer

  • Type: Method
  • Component: tvm_embedding_model

Performs inference using the embedding model.

Parameters

NameTypeDescriptionRequired
promptstringinput text to perform embedding

Outputs

NameTypeDescription
embeddingndarrayresult embedding (1-d array)

iterative: false

tokenize

  • Type: Method
  • Component: tvm_embedding_model

Performs tokenization on the input text and returns a list of tokens (input of deep learning).

Parameters

NameTypeDescriptionRequired
promptstringinput text to perform tokenization

Outputs

NameTypeDescription
tokensarray<int>result tokens

iterative: false

tvm_language_model

  • Type: Component
  • Module: language

Defines an on-device language model using TVM as the provider.

Parameters

NameTypeDescriptionRequired
modelstringModel name to use.
Available values: Qwen/Qwen3-0.6B, Qwen/Qwen3-1.7B, Qwen/Qwen3-4B, Qwen/Qwen3-8B
quantizationstringQuantization method.
Available values: q4f16_1 (defaults to q4f16_1)
modestringMode to initialize the model
Available values: interactive, local, server (defaults to interactive)

apply_chat_template

  • Type: Method
  • Component: tvm_language_model

Format inputs by it's model type.

Parameters

NameTypeDescriptionRequired
messagesarray<map>array of messages (OpenAI API compatible)
toolsarray<map> or stringtools to be used (defaults to empty string)
reasoningboolflag to enable reasoning (defaults to false)

Outputs

NameTypeDescription
promptstringresult prompt

iterative: false

infer

  • Type: Method
  • Component: tvm_language_model

Performs inference, generates outputs.

Parameters

NameTypeDescriptionRequired
messagesarray<map>array of messages (OpenAI API compatible)
toolsarray<map> or stringtools to be used (defaults to empty string)
reasoningboolflag to enable reasoning (defaults to false)

Outputs

NameTypeDescription
messagemapresult message from this iteration
finish_reasonstring or nullfinished reason.
Available values: stop, tool_call, length, error

iterative: true