Get started
First task: TypeScript
Send a task with durable identity from a server-side TypeScript application.
This server-side example sends one text task through an existing ready deployment. Keep the provider and model already configured for that deployment; the example uses the OpenAI-compatible Chat Completions protocol.
Before you start#
Get the deployment base URL, platform key, and provider credential from your connection setup. Persist TASK_SESSION_ID, TASK_OPERATION_ID, and a separate close-operation ID before running the example. Do not generate new identifiers merely to retry a timeout.
Use Node.js 22 or later for OpenAI TypeScript 7.15.0. The example pins that provider client and Integrity SDK 0.6.1, with provider retries and redirects disabled.
npm install @triage-integrity/integrity-sdk@0.6.1 openai@7.15.0Send and finish a task#
import OpenAI from "openai";
import { Integrity } from "@triage-integrity/integrity-sdk";
function required(name: string): string {
const value = process.env[name];
if (!value) throw new Error(`Missing ${name}`);
return value;
}
// Load IDs already persisted in your task and operation records.
const integrity = new Integrity({
apiKey: required("INTEGRITY_PLATFORM_KEY"),
baseUrl: required("INTEGRITY_BASE_URL"),
sessionId: required("TASK_SESSION_ID"),
});
const model = new OpenAI({
apiKey: required("CUSTOMER_PROVIDER_KEY"),
baseURL: integrity.baseUrl,
maxRetries: 0,
fetchOptions: { redirect: "error" },
timeout: 360_000,
});
const response = await model.chat.completions.create(
{
model: required("CUSTOMER_MODEL"),
messages: [{ role: "user", content: "Summarize this task's next step." }],
max_completion_tokens: 1024,
},
{ headers: integrity.headers(required("TASK_OPERATION_ID")) },
);
console.log(response.choices[0].message.content);The explicit token limit bounds the customer response. The timeout is an example client setting; match it to your deployment's documented budgets. The provider credential stays separate from the Integrity platform key.
Continue a longer task#
For a multi-step task, retain the same session ID and send a new persisted operation ID for each distinct model request. Include supported explicit history and tool results with their original call IDs. Call finish only when your application has finished the whole task; a final model message alone does not close it. In Observe each request is reviewed after its response, usually within a few minutes. A finish sent before the last review completes is accepted (HTTP 202) and the session closes when that review finishes; sending the same call again is safe.
// When the task is over and its last review has completed. Persist this ID separately.
await integrity.finish(required("TASK_CLOSE_OPERATION_ID"), "completed");This example does not execute tools. Before adding tools or external effects, implement the executor boundary.
Handle a hold or lost response#
A hold is not permission to continue or retry. After a lost connection or timeout, call integrity.recover(operation_id) in Python or integrity.recover(operationId) in TypeScript with the original identifiers. Inspect the durable result before deciding the next action. Do not repeat the model call automatically.
Open Runs to inspect the session. Read errors and recovery, streaming, and the SDK reference before extending the example.
Provider client options follow the official OpenAI TypeScript library reference. Integrity's supported protocol subset is described in Model connection.