llm.stream
Send a prompt to a language model and stream the events of the answer. The model can use tools and procedures
CLI- Package
- @procedures/llm · README
- Path
["llm","stream"]- CLI
mark llm stream --prompt <string>- As data
{"$proc":["llm","stream"],"input":{}}- Tags
- llm, anthropic, stream, tools
Use it
In TypeScript
import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/llm/register"; // registers its procedures
const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["llm","stream"], { prompt: "<prompt>" });
console.log(JSON.stringify(result));From the command line
$ mark llm stream --prompt <string>
As data, in a program
{ "$proc": ["llm", "stream"], "input": { "prompt": "<prompt>" } }Input
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
prompt | string | yes | The text of the user | |
system | string | no | The system text: the instructions to the model | |
model | string | no | The model (default: the model of the module, claude-sonnet-5-5) | |
maxTokens | integer | no | The most tokens of the output, with the thinking (default 16000) | |
temperature | number | no | The temperature, 0 to 1. Some models accept only the default | |
effort | "low" | "medium" | "high" | "xhigh" | "max" | no | The effort of the model (default: the default of the model) | |
timeoutMs | integer | no | The time limit of each request, in milliseconds (default 600000) | |
fallback | boolean | no | True: the API runs a declined request again on its fallback model (default: the option of the module, true) | |
tools | object[] | no | The tools that the model can use. The output gives each tool_use block | |
toolChoice | any | no | How the model uses the tools: auto (default), any, tool or none. Some models refuse any and tool | |
retries | integer | no | The new tries after a retryable error (429, 529, 5xx, a connection error), 0 to 10 (default: the option of the module, 2) | |
procedures | string[] | no | The procedures that the model can use as tools: the procedure calls them and sends the results back | |
maxRounds | integer | no | The most requests to the model in one call, 1 to 64 (default 8) |
Output
The schema does not list fields (any).
JSON Schemas
{
"input": {
"type": "object",
"properties": {
"prompt": {
"type": "string",
"minLength": 1,
"maxLength": 4000000,
"description": "The text of the user"
},
"system": {
"description": "The system text: the instructions to the model",
"type": "string",
"maxLength": 4000000
},
"model": {
"description": "The model (default: the model of the module, claude-sonnet-5-5)",
"type": "string",
"minLength": 1,
"maxLength": 200,
"pattern": "^[A-Za-z0-9][A-Za-z0-9._:@/-]*$"
},
"maxTokens": {
"description": "The most tokens of the output, with the thinking (default 16000)",
"type": "integer",
"minimum": 1,
"maximum": 64000
},
"temperature": {
"description": "The temperature, 0 to 1. Some models accept only the default",
"type": "number",
"minimum": 0,
"maximum": 1
},
"effort": {
"description": "The effort of the model (default: the default of the model)",
"type": "string",
"enum": [
"low",
"medium",
"high",
"xhigh",
"max"
]
},
"timeoutMs": {
"description": "The time limit of each request, in milliseconds (default 600000)",
"type": "integer",
"exclusiveMinimum": 0,
"maximum": 3600000
},
"fallback": {
"description": "True: the API runs a declined request again on its fallback model (default: the option of the module, true)",
"type": "boolean"
},
"tools": {
"description": "The tools that the model can use. The output gives each tool_use block",
"maxItems": 128,
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"pattern": "^[a-zA-Z0-9_-]{1,128}$",
"description": "The name of the tool"
},
"description": {
"description": "What the tool does and when the model uses it",
"type": "string",
"maxLength": 100000
},
"inputSchema": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {},
"description": "The JSON Schema of the input of the tool, with type object"
},
"strict": {
"description": "True: the API makes each input agree with the schema (strict tool use)",
"type": "boolean"
}
},
"required": [
"name",
"inputSchema"
]
}
},
"toolChoice": {
"oneOf": [
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "auto"
},
"disableParallelToolUse": {
"description": "True: the model uses at most one tool in an answer",
"type": "boolean"
}
},
"required": [
"type"
]
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "any"
},
"disableParallelToolUse": {
"description": "True: the model uses at most one tool in an answer",
"type": "boolean"
}
},
"required": [
"type"
]
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "tool"
},
"name": {
"type": "string",
"pattern": "^[a-zA-Z0-9_-]{1,128}$",
"description": "The tool that the model uses"
},
"disableParallelToolUse": {
"description": "True: the model uses at most one tool in an answer",
"type": "boolean"
}
},
"required": [
"type",
"name"
]
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "none"
}
},
"required": [
"type"
]
}
],
"description": "How the model uses the tools: auto (default), any, tool or none. Some models refuse any and tool"
},
"retries": {
"description": "The new tries after a retryable error (429, 529, 5xx, a connection error), 0 to 10 (default: the option of the module, 2)",
"type": "integer",
"minimum": 0,
"maximum": 10
},
"procedures": {
"description": "The procedures that the model can use as tools: the procedure calls them and sends the results back",
"maxItems": 64,
"type": "array",
"items": {
"type": "string",
"pattern": "^[A-Za-z0-9_-]+(\\.[A-Za-z0-9_-]+)*$"
}
},
"maxRounds": {
"description": "The most requests to the model in one call, 1 to 64 (default 8)",
"type": "integer",
"minimum": 1,
"maximum": 64
}
},
"required": [
"prompt"
]
},
"output": {
"oneOf": [
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "start"
},
"id": {
"type": "string",
"description": "The ID of the message"
},
"model": {
"type": "string",
"description": "The model that answers"
},
"usage": {
"type": "object",
"properties": {
"inputTokens": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "The tokens of the input that the cache did not have"
},
"outputTokens": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "The tokens of the output, with the thinking"
},
"cacheReadInputTokens": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "The tokens of the input from the cache"
},
"cacheCreationInputTokens": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "The tokens of the input that went into the cache"
}
},
"required": [
"inputTokens",
"outputTokens",
"cacheReadInputTokens",
"cacheCreationInputTokens"
],
"additionalProperties": false,
"description": "The tokens of the call"
}
},
"required": [
"type",
"id",
"model",
"usage"
],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "text"
},
"index": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "The index of the content block"
},
"text": {
"type": "string",
"description": "The new text"
}
},
"required": [
"type",
"index",
"text"
],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "tool_use"
},
"index": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "The index of the content block"
},
"id": {
"type": "string",
"description": "The ID of the tool_use block"
},
"name": {
"type": "string",
"description": "The name of the tool"
},
"input": {
"description": "The input of the call, or null when its JSON is not complete"
},
"partialJson": {
"description": "The JSON text of an input that does not parse",
"type": "string"
}
},
"required": [
"type",
"index",
"id",
"name",
"input"
],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "tool_call"
},
"round": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "The number of the request whose answer asked for the tool"
},
"id": {
"type": "string",
"description": "The ID of the tool_use block"
},
"name": {
"type": "string",
"description": "The name of the tool"
},
"procedure": {
"type": "string",
"description": "The key of the procedure"
},
"input": {
"description": "The input that the model gave"
}
},
"required": [
"type",
"round",
"id",
"name",
"procedure",
"input"
],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "The ID of the tool_use block"
},
"name": {
"type": "string",
"description": "The name of the tool"
},
"procedure": {
"type": "string",
"description": "The key of the procedure"
},
"input": {
"description": "The input that the model gave"
},
"isError": {
"type": "boolean",
"description": "True when the procedure failed: the model got the error"
},
"output": {
"description": "The output of the procedure"
},
"error": {
"description": "The error of the procedure",
"type": "string"
},
"type": {
"type": "string",
"const": "tool_result"
},
"round": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "The number of the request whose answer asked for the tool"
}
},
"required": [
"id",
"name",
"procedure",
"input",
"isError",
"type",
"round"
],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "stop"
},
"model": {
"type": "string",
"description": "The model of the last answer"
},
"stopReason": {
"type": "string",
"description": "Why the model stopped in the last answer"
},
"usage": {
"type": "object",
"properties": {
"inputTokens": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "The tokens of the input that the cache did not have"
},
"outputTokens": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "The tokens of the output, with the thinking"
},
"cacheReadInputTokens": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "The tokens of the input from the cache"
},
"cacheCreationInputTokens": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "The tokens of the input that went into the cache"
}
},
"required": [
"inputTokens",
"outputTokens",
"cacheReadInputTokens",
"cacheCreationInputTokens"
],
"additionalProperties": false,
"description": "The tokens of all the requests, added together"
},
"text": {
"type": "string",
"description": "The text of all the answers: all the text deltas, joined"
},
"toolUses": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "The ID of the tool_use block"
},
"name": {
"type": "string",
"description": "The name of the tool"
},
"input": {
"description": "The input of the call"
}
},
"required": [
"id",
"name",
"input"
],
"additionalProperties": false
},
"description": "The tool_use blocks of the last answer that no procedure ran"
},
"toolCalls": {
"description": "The calls of the procedure tools, in their sequence. Only with procedures",
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "The ID of the tool_use block"
},
"name": {
"type": "string",
"description": "The name of the tool"
},
"procedure": {
"type": "string",
"description": "The key of the procedure"
},
"input": {
"description": "The input that the model gave"
},
"isError": {
"type": "boolean",
"description": "True when the procedure failed: the model got the error"
},
"output": {
"description": "The output of the procedure"
},
"error": {
"description": "The error of the procedure",
"type": "string"
}
},
"required": [
"id",
"name",
"procedure",
"input",
"isError"
],
"additionalProperties": false
}
},
"rounds": {
"description": "The number of requests to the model. Only with procedures",
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991
},
"roundLimit": {
"description": "True when maxRounds stopped the loop before the model stopped. Only with procedures",
"type": "boolean"
}
},
"required": [
"type",
"model",
"stopReason",
"usage",
"text",
"toolUses"
],
"additionalProperties": false
}
],
"description": "One item of the stream: start, text, tool_use, tool_call, tool_result or stop"
}
}