|
| 1 | +Execute a chain of LLM calls sequentially, where each block's output becomes the next block's input. |
| 2 | + |
| 3 | +This endpoint initiates an asynchronous LLM chain job. The request is queued |
| 4 | +for processing, and results are delivered via the callback URL when complete. |
| 5 | + |
| 6 | +### Key Parameters |
| 7 | + |
| 8 | +**`query`** (required) - Initial query input for the first block in the chain: |
| 9 | +- `input` (required): User question/prompt/query — accepts a plain string, a structured input object (`text`, `audio`, `image`, `pdf`), or a list of structured inputs |
| 10 | +- `conversation` (optional, object): Conversation configuration |
| 11 | + - `id` (optional, string): Existing conversation ID to continue |
| 12 | + - `auto_create` (optional, boolean, default false): Create new conversation if no ID provided |
| 13 | + - **Note**: Cannot specify both `id` and `auto_create=true` |
| 14 | + |
| 15 | + |
| 16 | +**`blocks`** (required, array, min 1 block) - Ordered list of blocks to execute sequentially. Each block contains: |
| 17 | + |
| 18 | +- `config` (required) - Configuration for this block's LLM call (just choose one mode): |
| 19 | + |
| 20 | + - **Mode 1: Stored Configuration** |
| 21 | + - `id` (UUID): Configuration ID |
| 22 | + - `version` (integer >= 1): Version number |
| 23 | + - **Both required together** |
| 24 | + - **Note**: When using stored configuration, do not include the `blob` field in the request body |
| 25 | + |
| 26 | + - **Mode 2: Ad-hoc Configuration** |
| 27 | + - `blob` (object): Complete configuration object |
| 28 | + - `completion` (required, object): Completion configuration |
| 29 | + - `provider` (required, string): Kaapi providers (`openai`, `google`, `sarvamai`) — params are validated and mapped internally. Native providers (`openai-native`, `google-native`, `sarvamai-native`) — params are passed through as-is |
| 30 | + - `type` (required, string): Completion type — `"text"`, `"stt"`, or `"tts"` |
| 31 | + - `params` (required, object): Parameters structure depends on provider and type (see schema for detailed structure) |
| 32 | + - `input_guardrails` (optional, array): Guardrails applied to validate/sanitize input before the LLM call |
| 33 | + - `output_guardrails` (optional, array): Guardrails applied to validate/sanitize output after the LLM call |
| 34 | + - `prompt_template` (optional, object): Template for text interpolation |
| 35 | + - `template` (required, string): Template string with `{{input}}` placeholder — replaced with the block's input before execution |
| 36 | + - **Note** |
| 37 | + - When using ad-hoc configuration, do not include `id` and `version` fields |
| 38 | + - When using the Kaapi abstraction, parameters that are not supported by the selected provider or model are automatically suppressed. If any parameters are ignored, a list of warnings is included in the metadata.warnings. |
| 39 | + - **Recommendation**: Use stored configs (Mode 1) for production; use ad-hoc configs only for testing/validation |
| 40 | + - **Schema**: Check the API schema or examples below for the complete parameter structure for each provider type |
| 41 | + |
| 42 | +- `include_provider_raw_response` (optional, boolean, default false): |
| 43 | + - When true, includes the unmodified raw response from the LLM provider for this block |
| 44 | + |
| 45 | +- `intermediate_callback` (optional, boolean, default false): |
| 46 | + - When true, sends an intermediate callback after this block completes with the block's response, usage, and position in the chain |
| 47 | + |
| 48 | +**`callback_url`** (optional, HTTPS URL): |
| 49 | +- Webhook endpoint to receive the final response and intermediate callbacks |
| 50 | +- Must be a valid HTTPS URL |
| 51 | +- If not provided, response is only accessible through job status |
| 52 | + |
| 53 | +**`request_metadata`** (optional, object): |
| 54 | +- Custom JSON metadata |
| 55 | +- Passed through unchanged in the response |
| 56 | + |
| 57 | +### Note |
| 58 | +- If any block fails, the chain stops immediately — no subsequent blocks are executed |
| 59 | +- `warnings` list is automatically added in response metadata when using Kaapi configs if any parameters are suppressed or adjusted (e.g., temperature on reasoning models) |
| 60 | + |
| 61 | +--- |
0 commit comments