Status and streams
Settlement and KYC dispositions after the call returns: paymentStatus, paymentStatusStream, verificationStatus, verificationStatusStream.
Status and streams
A payment or a KYC check does not finish when the tool call returns: the provider settles or decides later and reports it by webhook. These four methods correlate a tool_call_id (the one execute returns) back to the latest known disposition. Two poll; two hold an SSE stream open and resolve with the last envelope.
The streams share one lifecycle: the server pushes a snapshot event with the current state on open, an update per transition, a heartbeat every 15 seconds so proxies keep the connection, and a done event after a terminal state, followed by a 5-second grace period before it closes. The promise resolves with the last envelope seen, so a caller that only wants the terminal state can await without wiring onUpdate. The polling siblings stay available.
paymentStatus
paymentStatus(toolCallId: string): Promise<PaymentStatusResult>The settlement state of a codespar_charge or codespar_pay call. payment_status is independent of the execute-time result in original_status: a successful execute can still be pending, and a settled payment can later be refunded. unknown means the call carried no idempotency key (a legacy or non-meta-tool call), so there is nothing to correlate.
| Parameter | Type | Required | Description |
|---|---|---|---|
toolCallId | string | yes | The tool_call_id from the ToolResult of the payment call |
let = await .("tc_0000000000000000");
while (. === "pending") {
await new (() => (, 2000));
= await .("tc_0000000000000000");
}
.(., ..);interface PaymentStatusResult {
tool_call_id: string;
payment_status: "pending" | "succeeded" | "failed" | "refunded" | "updated" | "unknown";
/** Null for legacy / non-meta-tool calls */
idempotency_key: string | null;
/** The execute-time status (success/error) */
original_status: string;
events: PaymentStatusEvent[];
}
interface PaymentStatusEvent {
event_type: string;
received_at: string;
provider: string | null;
provider_action: string | null;
payment_id: string | null;
}Throws a CodesparApiError on a non-2xx answer (a 404 for an id the caller's organization does not own) or a transport failure, a TimeoutError on timeout.
Related REST GET /v1/tool-calls/{id}/payment-status, Webhooks for the events this reads.
paymentStatusStream
paymentStatusStream(toolCallId: string, options?: PaymentStatusStreamOptions): Promise<PaymentStatusResult>The SSE sibling of paymentStatus. Every onUpdate receives the same envelope shape paymentStatus returns, so one renderer serves both. signal cancels from the caller side; the backend sees a normal disconnect. The timeout is an idle timeout that resets on every complete SSE frame, heartbeats included.
| Parameter | Type | Required | Description |
|---|---|---|---|
toolCallId | string | yes | The tool_call_id of the payment call |
options | PaymentStatusStreamOptions | no | onUpdate, signal, timeout (ms) |
const = new ();
const = await .("tc_0000000000000000", {
: () => .("payment:", .),
: .,
});
.("terminal:", .);interface PaymentStatusStreamOptions {
onUpdate?: (envelope: PaymentStatusResult) => void;
signal?: AbortSignal;
/** Idle timeout in ms; overrides the client default */
timeout?: number;
}Throws the caller's abort reason when signal fires; a TimeoutError when no frame arrives within the idle timeout; a CodesparApiError when the response is not 2xx or the transport fails; a plain Error if the stream closes before its first snapshot.
Related REST GET /v1/tool-calls/{id}/payment-status/stream.
verificationStatus
verificationStatus(toolCallId: string): Promise<VerificationStatusResult>The disposition of a codespar_kyc call. After the call returns, the subject completes the hosted flow off-platform; this reads the latest state the provider reported. Priority when several events exist: approved over rejected over review over expired over pending. hosted_url is the buyer-facing link when the rail has one, null for server-side scoring rails.
| Parameter | Type | Required | Description |
|---|---|---|---|
toolCallId | string | yes | The tool_call_id of the KYC call |
const = await .("tc_0000000000000000");
if (. === "approved") {
// proceed
} else if (.) {
.("finish here:", .);
}interface VerificationStatusResult {
tool_call_id: string;
verification_status: "pending" | "approved" | "rejected" | "expired" | "review" | "unknown";
idempotency_key: string | null;
original_status: string;
/** Buyer-facing verification URL; null for server-side scoring rails */
hosted_url: string | null;
events: VerificationStatusEvent[];
}
interface VerificationStatusEvent {
event_type: string;
received_at: string;
provider: string | null;
verification_id: string | null;
}Throws as paymentStatus.
Related REST GET /v1/tool-calls/{id}/verification-status, codespar_kyc.
verificationStatusStream
verificationStatusStream(toolCallId: string, options?: VerificationStatusStreamOptions): Promise<VerificationStatusResult>The SSE sibling of verificationStatus, with the same lifecycle as paymentStatusStream: snapshot on open, an update per change, close after a terminal disposition.
| Parameter | Type | Required | Description |
|---|---|---|---|
toolCallId | string | yes | The tool_call_id of the KYC call |
options | VerificationStatusStreamOptions | no | onUpdate, signal, timeout (ms) |
const = await .("tc_0000000000000000", {
: () => .("kyc:", .),
});
.(.);interface VerificationStatusStreamOptions {
onUpdate?: (envelope: VerificationStatusResult) => void;
signal?: AbortSignal;
/** Idle timeout in ms; overrides the client default */
timeout?: number;
}Throws as paymentStatusStream.
Related REST GET /v1/tool-calls/{id}/verification-status/stream.