.end().
All setter methods return this, so you can chain calls:
Required
Create step
Create a step from a run:| Parameter | Required | Description |
|---|---|---|
stepId | No | Custom step ID. If not provided, a UUID is automatically generated. |
Set prompt
The prompt is required before calling.end().
| Parameter | Required | Description |
|---|---|---|
text | Yes | The prompt sent to the LLM |
Set response
The response is required before calling.end().
| Parameter | Required | Description |
|---|---|---|
text | Yes | The response returned by the LLM |
End step
End the step. A step must have both a prompt and a response set before calling.end(). The step cannot be modified after calling .end().
Optional step data
Set model
Track which model was used. You can use the shorthand or provide both requested and used models.| Parameter | Required | Description |
|---|---|---|
name | No | The model name (shorthand) |
requested | No | The model that was requested |
used | No | The model that was actually used |
Set token usage
Track token counts for the step.| Parameter | Required | Description |
|---|---|---|
uncached | No | Number of uncached prompt tokens |
cached | No | Number of cached prompt tokens |
completion | No | Number of completion tokens |
Set cost
Track the cost of the step in USD.| Parameter | Required | Description |
|---|---|---|
amount | Yes | The total cost of the step in USD |
Set finish reason
Set the finish reason returned by the LLM.| Parameter | Required | Description |
|---|---|---|
reason | Yes | The finish reason returned by the LLM (e.g. "stop", "tool_call") |
Set tool definitions
Set the tool definitions available to the LLM for this step.| Parameter | Required | Description |
|---|---|---|
definitions | Yes | The tool definitions available to the LLM (string or array) |
Mark step as failed
Sets the status code to error. The step cannot be modified after calling.error(). Unlike .end(), calling .error() does not require a prompt or response to be set.
| Parameter | Required | Description |
|---|---|---|
statusMessage | No | A description of the error |
Factory pattern
If you have all step data available upfront, use thesendStep function:
