Getting Started with Kaya
Write your first Kaya program
Your First Program
A Kaya program is a sequence of statements. Bare strings become chat output, and
{{...}} interpolates values:
// Simple output
"Hello, world!"
// Variables
let name = "Alice"
"Welcome, {{name}}!"
// Expressions
let temp = 30
let tomorrow = temp + 1
"Tomorrow it'll be {{tomorrow}} degrees"Save that source as hello.kaya, then run it with the installed CLI:
kaya run hello.kayakaya starts the local daemon automatically when needed. See the
command-line reference for workflow inputs,
YAML launch profiles, session commands, and manual daemon controls.
This first program needs no model provider. Later examples that generate text need the native model setup.
Program Structure
Kaya programs execute statements sequentially from top to bottom. This outline
assumes a local utils.kaya module exporting helper(data: json):
// 1. Type definitions (optional, loaded first)
type User = {
name: string,
score: number
}
// 2. Imports (optional, loaded first)
import helper from "./utils"
// 3. Executable statements
let user = {name: "Bob", score: 25}
"User: {{user.name}}"
// 4. Function calls
helper(data: user)Important: Type definitions and imports are always processed first, regardless of where they appear in the file.
Variables
Use let to create variables:
// Primitives
let name = "Alice"
let temp = 30
let isActive = true
// Objects
let user = {
name: "Alice",
email: "alice@example.com"
}
// Arrays
let numbers = [1, 2, 3, 4, 5]
let names = ["Alice", "Bob", "Charlie"]
// Accessing data
let firstName = user.name
let firstNumber = numbers[0]Expressions
Kaya supports familiar expressions. This example supplies its own inputs:
let a = 10
let b = 20
let temp = 30
let isActive = true
let score = 75
let name = "Alice"
// Arithmetic
let sum = 10 + 5
let product = 4 * 7
let average = (a + b) / 2
// Comparison
if temp >= 30 {
"Hot"
}
// Logical operators
if isActive && score > 50 {
"Qualified"
}
// String interpolation
let greeting = "Hello, {{name}}! It's {{temp}} degrees."Functions
Define reusable functions:
// Basic function
function greet(name: string) {
"Hello, {{name}}!"
}
// Call it
greet(name: "Alice")
// With return value
function add(a: number, b: number): number {
return a + b
}
let result = add(a: 10, b: 5)
"10 + 5 = {{result}}"Control Flow
If Statements
let temp = 25
if temp >= 30 {
"Hot"
} else if temp >= 15 {
"Warm"
} else {
"Cold"
}Loops
// For loop with range
for i in range(5) {
"Iteration {{_index}}"
}
// For loop with array
let fruits = ["apple", "banana", "cherry"]
for fruit in fruits {
"I like {{fruit}}"
}
// While loop
let count = 0
while count < 5 {
"Count: {{count}}"
count = count + 1
}Note: Use bare assignment (count = count + 1) to update a loop variable.
let count = ... inside the loop body would declare a new block-scoped
variable that's discarded each iteration — the outer count never changes and
the loop runs forever.
AI Generation
One of Kaya's core features is built-in AI generation. First configure the
gemini-fast alias using Text model bindings,
then run this program:
// Generate text with an LLM
let poem = generate(
message: "Write a short haiku about coding",
model: "gemini-fast"
)
"Here's your poem:"
"{{poem}}"gemini-fast is a deployment alias. The tool-server manifest binds it to a
provider and upstream model, and the session must grant its route. A provider
key alone creates neither a binding nor a grant. Restart an existing daemon
after changing its configuration. Calls that omit model also need a configured
session default; automatic local setup does not choose one.
See Generating Text for complete details.
Type Safety
Add types for runtime validation:
type Email = string + { email: true }
type Score = number + { int: true, min: 0, max: 100 }
type User = {
name: string + { min: 1 },
email: Email,
score: Score
}
// This validates at runtime
let user: User = {
name: "Alice",
email: "alice@example.com",
score: 30
}
// Expected validation failure: run this separately from the valid example
let badUser: User = {
name: "", // ❌ Too short
email: "not-an-email", // ❌ Invalid email
score: 150 // ❌ Above max
}Comments
// Single-line comment
/*
Multi-line comment
spanning multiple lines
*/
/* Also works inline */ "code" // Another commentNext Steps
Now that you know the basics:
- Syntax Basics - Deep dive into variables, types, and expressions
- Functions - Parameters, returns, closures, and advanced patterns
- Control Flow - Mastering if, loops, and map
- Generating Text - Using LLMs and tools