Crux
API Reference@use-crux/core

Request evidence

Preview prospective fit and inspect redacted evidence from executed requests.

import {
  inspectRequest,
  preview,
  RequestCompositionError,
  RequestInspectionUnavailableError,
} from "@use-crux/core";

Use preview() before execution and request receipts after execution. Preview is observational and cannot be passed to a provider. Receipts describe one exact sealed provider call.

preview(target, options?)

preview() plans the initial Prompt or Agent request without executing it.

const request = await preview(responder, {
  input: { ticketId: "ticket_4821" },
  inputBudget: { max: 22_000 },
});

Use preview for preflight checks, development tools, and fit tests. It does not generate summaries, publish offloads, run Tools or preparation hooks, schedule maintenance, or write canonical state.

OptionUse
inputResolve the Prompt's typed input.
modelSupply a concrete model for a Prompt. An Agent may use its configured model.
providerApply provider-specific Prompt adaptation.
messagesSupply caller-owned canonical history.
inputBudgetPreview per-call pressure settings.
settingsInclude settings that affect request shape or output reserve.
toolsInclude call-site Tools in measurement.
StatusMeaning
fitsA ready complete request fits.
over-limitNo legal complete request fits. This expected result does not throw.
unknownRuntime-only sources or unprepared artifacts prevent a complete answer.

RequestPreview.measurement is exact, estimated, conservative, or incomplete. PreviewAdaptation.state is selected or unprepared. Preview throws for invalid input or composition, and throws TypeError when no concrete model is available.

RequestReceipt

Every executed provider step exposes a small JSON-safe receipt:

const receipt = result.steps[0].request;
console.log(receipt.inputTokens, receipt.adaptations);

Use enumerable receipt fields for logs and durable result payloads. The common exact request has adaptations: [].

FieldMeaning
idIdentity of the sealed provider request.
modelConcrete selected model.
inputTokensMeasured complete-request input.
maxInputTokensEffective strict input maximum.
measurementexact, estimated, or conservative.
adaptationsAuthorized deviations from full exact representations.
warningsNon-fatal content-free warnings.
previousRequestIdPrevious semantic call in the same managed loop.
inspect()Full redacted evidence retained with the live receipt.

RequestAdaptation identifies the contributor and selected authored, summary, offload, or omitted representation. Optional token fields show the full and selected complete-request sizes. RequestWarning contains a safe code and message.

Full inspection

const inspection = await receipt.inspect();
console.table(inspection.breakdown.contributions);
console.table(inspection.candidates);
Inspection fieldPurpose
contributionsRequired, sticky, or elastic boundaries and their authorized rungs.
candidatesAvailability, selection, size, and rejection reason.
breakdownLargest-first token attribution by safe contribution class.
countingMeasurement confidence, safety margin, and provider overhead.
retryCountAdapter-reported transport retries for this sealed request.
artifactsSummary or offload evidence.
supportToolsRequired support Tool identities.
supportRequestsRedacted receipts for linked summary calls.
linkedRequestIdsPrevious and support request identities.
preparationAccepted amendment counts and resource hashes.

Inspection never includes authored prompt, message, Tool-result, resource, or schema content.

inspectRequest(receiptOrId)

inspectRequest() restores evidence for a live receipt, serialized receipt, or request id.

const serialized = JSON.parse(JSON.stringify(receipt));
const inspection = await inspectRequest(serialized);

Use it after JSON transport or from another process when your observability destination retains request evidence. Prefer receipt.inspect() for a live result. Process-local standalone retention keeps at most 256 requests for five minutes.

After eviction or expiry, lookup throws RequestInspectionUnavailableError with code REQUEST_INSPECTION_UNAVAILABLE. The small receipt remains valid.

RequestCompositionError

Catch this error when you need to choose a user-facing remedy:

try {
  return await generate(responder, options);
} catch (error) {
  if (error instanceof RequestCompositionError) {
    logger.warn({ code: error.code, diagnostics: error.diagnostics });
  }
  throw error;
}
CodeCause
REQUEST_TOO_LARGEThe minimum legal complete request exceeds the effective maximum.
REPRESENTATION_UNAVAILABLEA required summary, reference, or support capability is not ready.
INVALID_COMPOSITIONA ladder, history policy, capability graph, or amendment is invalid.

RequestDiagnostic carries a safe id, machine code, optional contributor and token count, and an actionable message. Sensitive content remains redacted.

Public type inventory

AreaPublic exports
PreviewRequestPreviewTarget, RequestPreviewOptions, RequestPreview, PreviewAdaptation, PreviewAdaptationState
ReceiptRequestReceipt, RequestAdaptation, RequestWarning, RequestInspection, RequestContributionInspection, RequestCandidateInspection, RequestArtifactInspection, RequestSupportReceipt, RequestTokenBreakdown, RequestTokenBreakdownEntry
ErrorsRequestCompositionErrorCode, RequestDiagnostic

On this page