Skip to main content

Status and streams

Settlement and KYC dispositions after the call returns: paymentStatus, paymentStatusStream, verificationStatus, verificationStatusStream.

2 min read
View MarkdownEdit on GitHub

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

ReadpaymentStatus(toolCallId: string): Promise<PaymentStatusResult>
Pythonsession.payment_status(tool_call_id)

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.

ParameterTypeRequiredDescription
toolCallIdstringyesThe tool_call_id from the ToolResult of the payment call
Example
let  = await .("tc_0000000000000000");
while (. === "pending") {
  await new (() => (, 2000));
   = await .("tc_0000000000000000");
}
.(., ..);
Result: PaymentStatusResult
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

StreampaymentStatusStream(toolCallId: string, options?: PaymentStatusStreamOptions): Promise<PaymentStatusResult>
since 0.9.0Pythonsession.payment_status_stream(tool_call_id, on_update=..., timeout=...)

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.

ParameterTypeRequiredDescription
toolCallIdstringyesThe tool_call_id of the payment call
optionsPaymentStatusStreamOptionsnoonUpdate, signal, timeout (ms)
Example
const  = new ();
const  = await .("tc_0000000000000000", {
  : () => .("payment:", .),
  : .,
});
.("terminal:", .);
PaymentStatusStreamOptions
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

ReadverificationStatus(toolCallId: string): Promise<VerificationStatusResult>
Pythonsession.verification_status(tool_call_id)

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.

ParameterTypeRequiredDescription
toolCallIdstringyesThe tool_call_id of the KYC call
Example
const  = await .("tc_0000000000000000");
if (. === "approved") {
  // proceed
} else if (.) {
  .("finish here:", .);
}
Result: VerificationStatusResult
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

StreamverificationStatusStream(toolCallId: string, options?: VerificationStatusStreamOptions): Promise<VerificationStatusResult>
since 0.9.0Pythonsession.verification_status_stream(tool_call_id, on_update=..., timeout=...)

The SSE sibling of verificationStatus, with the same lifecycle as paymentStatusStream: snapshot on open, an update per change, close after a terminal disposition.

ParameterTypeRequiredDescription
toolCallIdstringyesThe tool_call_id of the KYC call
optionsVerificationStatusStreamOptionsnoonUpdate, signal, timeout (ms)
Example
const  = await .("tc_0000000000000000", {
  : () => .("kyc:", .),
});
.(.);
VerificationStatusStreamOptions
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.

Status and streams | CodeSpar