Get started

Send requests from code

Ask for approval from TypeScript, Python or plain HTTP, wait for the decision, and run only the approved arguments.

About 5 minutes

Transcript (30 seconds)

Ask for approval from your own code.

Install the SDK and set your API key.

Call requestAndWait with the action, its arguments and a reason.

A person approves, edits or rejects.

Your code runs only the approved arguments.

Before you start

Steps

  1. Install the SDK

    Both SDKs have no dependencies.

    npm install @promptcompute/sdk
    # or
    pip install promptcompute
  2. Set your key

    Store the key as a secret. The SDKs read PROMPTCOMPUTE_API_KEY.

    export PROMPTCOMPUTE_API_KEY=pc_test_...
  3. Ask and wait

    requestAndWait sends the request and waits for a decision. It throws on reject, deny or expiry, so the action never runs without approval.

    import { PromptCompute } from "@promptcompute/sdk";
    
    const pc = new PromptCompute();
    const decision = await pc.requestAndWait({
      action: "payment.refund",
      args: { order_id: "A-1001", amount: 120 },
      reason: "Customer reported damage",
    });
    await refund(decision.final_args); // never the original args
  4. Or wrap a function

    withApproval returns a function that asks first and runs with the approved arguments. In Python, use the @requires_approval decorator.

    from promptcompute import requires_approval
    
    @requires_approval(action="payment.refund")
    def refund(order_id: str, amount: float) -> None:
        ...
  5. Plain HTTP

    POST the request, then long-poll its wait endpoint for up to 50 seconds at a time.

    curl -X POST https://api.promptcompute.ai/v1/approvals \
      -H "Authorization: Bearer $PROMPTCOMPUTE_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"action":"payment.refund","args":{"order_id":"A-1001","amount":120}}'
    
    curl "https://api.promptcompute.ai/v1/approvals/apr_.../wait?timeout=50" -H "Authorization: Bearer $PROMPTCOMPUTE_API_KEY"

Use cases

A batch job that changes billing

The situation
A nightly job adjusts customer plans and you want a person on anything above a threshold.
What to do
Wrap the change in withApproval with an idempotency key from the run id.
What happens
Retries never ask twice, and changes run only with the approved values.

An agent framework

The situation
Your agent runs on LangGraph, the OpenAI Agents SDK, Temporal or Inngest.
What to do
Use the adapter from @promptcompute/sdk for your framework instead of writing the wait loop.
What happens
The run pauses at the step that needs approval and resumes with the decision.

What you will see

Your code waits at the request, and continues with final_args once someone approves.

It worked when

Example output: requestAndWait after an approver lowered the amount

{
  "id": "apr_01j...",
  "status": "approved_with_edits",
  "action": "payment.refund",
  "args": { "order_id": "A-1001", "amount": 120 },
  "final_args": { "order_id": "A-1001", "amount": 80 },
  "risk": "medium",
  "rule_id": "larger-refunds"
}

If something goes wrong

401 unauthorized
The key is missing, malformed or revoked. Keys start with pc_live_ or pc_test_; create a new one under API keys.
402 quota_exceeded
The Free plan is past 120% of its monthly requests. Upgrade under Billing, or use the test environment, which is never limited.
Unknown actions always need approval at high risk
Register the action under Action types, or import it from the starter catalog, so it gets a summary and the right risk.