Skip to main content
The SDK packages are being released to the public registries. Until the install commands are shown in the quickstart, do not install a package of these names from anywhere else. The cURL samples run as written against a sandbox, with a test key in INSIGHTCHAIN_API_KEY; the quickstart sets both up. The TypeScript and Python samples run as written once the SDK is installed.

Push your purchase orders, get stockout risk back

Send the purchase orders you have open and read back which are at risk, and where stock runs out first. Scopes: ingest, read ingest writes and reads nothing back, so the reads need read on the same key or on a second one. Step 1. Push the orders. A record is matched on external_id, so sending it again updates it, and an Idempotency-Key makes a retry safe. The sample sends one order that is already late, for an item, a supplier and a location of the sandbox’s demo data. With your own data, push suppliers, items and locations the same way first.
Step 2. Read the risk of each open order for that item: a score, what drives it, and what to do about it (expedite, monitor or on_track).
Step 3. Read when the item runs out at each location, with the inbound orders counted in.
Step 4. List what is proposed. A sandbox lists the proposals it was loaded with.
What comes back. The push answers with a count per entity (received, upserted, failed) and the records it refused. A risk row carries purchase_order, risk_score, recommended_action and the factors behind the score. A projection carries on_hand, stockout_in_days and whether inbound stock arrives in time (rescued_by_inbound).

Check what a tariff costs before you buy

Price an import before you place the order: the duty on the tariff line, then the full landed cost. Scopes: read Step 1. Check the duty on the tariff line from the country you would buy from. Send item_description in place of hs_code when you do not have the code.
Step 2. Price the shipment: duty, fees and import tax on top of the goods, freight and insurance, in total and per unit.
Step 3. Compare the countries you could buy from: the same shipment, one call per origin.
What comes back. The tariff check returns the base rate, every additional duty with its source, and the effective_rate. The landed cost returns a cost_breakdown (duty, fees, import tax), total_landed_cost and per_unit_landed_cost.

Act on a recommendation

Read what is proposed and why, then approve it or turn it down. Scopes: read, execute, approve read lists and explains. execute decides a recommendation and proposes an order. approve approves or rejects an order: only an organization admin can put it on a key, and it is held by someone other than the proposer. Step 1. List what is waiting for a decision, highest priority first.
Step 2. Read why it was proposed: the evidence, the numbers behind it and how confident it is.
Step 3. Decide. Approving needs the execute scope and is recorded for the person who created the key. To turn it down, call dismissRecommendation (dismiss_recommendation) the same way.
Step 4. Where the recommendation is an order (a transfer, a purchase, an expedite, a markdown), propose the order with execute. A second organization admin then approves or rejects it with a key that holds approve: send action: "approve" or "reject" with the order’s id as order_id. The person who proposed an order cannot approve it. A recommendation that is a task for a person is refused here, and the sample prints why.
What comes back. A recommendation carries its kind, priority, quantity, the item and locations, and its status. The explanation carries the evidence (headline, drivers, cost and benefit, confidence) and a narrative. A decision returns the recommendation with its new status; a proposed order returns the order with status proposed.

Get told when something changes

Receive a signed request at your own address when something changes, and check that it came from us. Scopes: approve The key’s creator must be an organization admin. A webhook registered with a test key receives test events only. Step 1. Register the address that will receive events, and the kinds it wants. The signing secret is in this answer only: store it where your receiver reads it. Set WEBHOOK_URL to a public https address of your own before running the samples of this recipe.
Step 2. In your receiver, check X-InsightChain-Signature-V2 against the raw body before you trust it: t=<unix seconds>,v1=<hex HMAC-SHA256 of "<t>.<raw body>">, keyed with the secret. Refuse a timestamp more than 300 seconds from your clock. The sample runs on its own.
Step 3. Send a test event. It is signed like any delivery, sent once, and the answer says how your receiver replied.
Step 4. Read the delivery log: one row per attempt for the last 30 days, with what your receiver answered and how long it took.
Step 5. Send a failed delivery again once your receiver is fixed. delivery_id is the X-InsightChain-Delivery header your receiver got. A delivery still being retried answers 409 delivery_pending. A sandbox sends test events only, and a test event is sent once, so there the sample finds nothing to send again.
Step 6. Rotate the secret without dropping a delivery. With overlap_seconds the old secret keeps signing beside the new one until the window ends: the header carries two v1 values, the new secret’s first, and the check above accepts either. Deploy the new secret to your receiver inside the window.
What comes back. Registering returns the webhook and its secret, once. A test returns delivered, the outcome and your receiver’s status. The delivery log returns one row per attempt: event_type, trigger, outcome, status, duration_ms and, for an attempt that will be retried, next_attempt_at.

Keep your keys healthy

See which keys are in use, give each an expiry, and rotate one without downtime. Scopes: keys, read Only an organization admin can put keys on a key, and the key works while its creator is still an admin. It manages keys of its own environment: a test key the sandbox’s keys, a live key the live ones. Step 1. List the keys: what each may do, when it was last used and when it expires. A key that has not been used for months is one to revoke.
Step 2. Create a key for one job, with only the scopes the job needs and a date it stops working. A key can hand out only scopes it holds itself, so this call needs read as well as keys.
Step 3. Rotate it with a 24-hour overlap: the new secret works at once and the old one keeps working until the window ends, so you can deploy the new one without a gap. Without overlap_seconds the old secret stops at once.
Step 4. Change when it expires. Past expires_at the key answers 401 api_key_expired. Send null for a key that does not expire.
Step 5. Revoke a key you no longer need. It stops working at once.
What comes back. Every key comes back without its secret: name, key_hint (the prefix and last four characters), scopes, environment, last_used_at (to the minute), expires_at and requests_today. Creating and rotating also return secret, once. Every change is in your audit trail.

Find a failed call

Trace one call from your own logs to ours, and see what failed lately. Scopes: read Step 1. Send your own id with the call, as X-Request-ID (1 to 128 visible characters). The answer keeps ours in X-Request-ID and echoes yours as X-Client-Request-ID. The sample asks for a recommendation that does not exist, so the call fails.
Step 2. Find the call by your id. An entry appears a moment after its answer has left.
Step 3. Or list what failed lately. Filter by outcome, status, method, api_key_id, or a time range with since and until.
Step 4. See how much of each key’s daily quota is used, and requests and failures per key and day.
What comes back. A log entry carries request_id, your client_request_id, the key, method, the route as a template, status, error_code, latency_ms and whether it came over http or mcp. It never carries a body, a query value or an id from the path. Entries are kept 30 days. Calls made without a valid key are not logged.

Connect an agent

An assistant can call the same operations as tools: add the server to the client your team already uses and sign in with your account, or give a script an API key. Setup for each client, and the tools by the question they answer, are on their own page. See Connect an AI client.