Generate text
zai.text() generates content from a prompt:
| Option | Type | Description |
|---|---|---|
length | number | Target length in tokens |
Rewrite text
zai.rewrite() transforms text based on instructions:
| Option | Type | Description |
|---|---|---|
length | number | Max tokens to generate |
examples | Array<{input, output, instructions?}> | Few-shot examples to guide the rewriting |
Summarize
zai.summarize() condenses long content. It handles documents from a few paragraphs up to entire books by chunking and merging automatically:
| Option | Type | Description |
|---|---|---|
length | number | Target summary length in tokens |
prompt | string | Instructions for what to focus on |
format | string | How to format the output (e.g. “bullet points with clear sections”) |
intermediateFactor | number | How many times longer intermediate summaries are than the final length (used for very large documents) |
maxIterations | number | Max refinement passes |
sliding | { window, overlap } | Override the default chunk size and overlap |
Answer with citations
zai.answer() answers a question from a set of documents and tells you which documents backed the answer. It doesn’t always return a direct answer: if the question is ambiguous, off-topic, or the documents don’t cover it, the result carries that information instead.
result.type to handle the other cases (ambiguous questions, off-topic, etc.):
| Type | Fields | When it’s returned |
|---|---|---|
answer | answer, citations | The documents support a clear answer |
ambiguous | ambiguity, follow_up, answers | The question has multiple valid interpretations |
out_of_topic | reason | The question isn’t covered by the documents’ topic |
invalid_question | reason | The question is malformed or nonsensical |
missing_knowledge | reason | The topic is relevant but the documents don’t cover it |
Patch files
zai.patch() makes surgical edits to code or text files based on natural language instructions. It produces minimal diffs rather than regenerating entire files: