Skip to main content
REST client

Policies

The 6 operations under policies, as typed calls on the generated REST client.

2 min read
View MarkdownEdit on GitHub

Available from @codespar/sdk 0.12.0; the version on npm is 0.16.18. When these docs build, the examples on this page are compiled against @codespar/sdk 0.16.18, the version this site installs: a call that does not type-check against it fails the build.

Every call below is cs.api reaching one operation of the OpenAPI document this page was generated from; the REST client overview explains request, response, the option bag and the errors. The values are placeholders shaped by the document.

import {  } from "@codespar/sdk";

const  = new ({ : .. });

GET /v1/policies

List policy rules for the authenticated org, sorted by order ASC.

const  = await ..("/v1/policies");

Parameters, body and every documented response: GET /v1/policies in the HTTP reference.

POST /v1/policies

Create a new policy rule. A budget rule counts DECLARED intent, not money that left: the cost is added to the agent's daily and monthly counters when the call is evaluated, before anything is sent (the payment amount on consumer payments; for an agent's codespar_pay, the amount of the call; for any other tool on session execute, the caller's estimatedCost). The counters are kept in major units of BRL: a codespar_pay of amount 2500 in BRL counts 25, and the estimatedCost a caller declares beside a codespar_pay is not counted. A codespar_pay in another currency, or with no amount, is allowed and counts nothing, and so does every other outbound meta-tool; the API logs budget rule matched without derivable cost each time a budget rule lets one through. A consumer payment that provably moved nothing (refused before dispatch, or refused by the provider) gives its cost back; one whose outcome is uncertain stays counted. A codespar_pay counted through the meta-tool path is not given back when it fails.

const  = await ..("/v1/policies", {
  : {
    : "Example",
    : "deny",
    : [],
    : [],
    : true
  }
});

Parameters, body and every documented response: POST /v1/policies in the HTTP reference.

POST /v1/policies/reorder

Reorder policy rules. Atomic: if any id does not belong to the org, the entire operation rolls back and returns 404.

const  = await ..("/v1/policies/reorder", {
  : {
    : [
      "string"
    ]
  }
});

Parameters, body and every documented response: POST /v1/policies/reorder in the HTTP reference.

GET /v1/policies/{id}

Read one policy rule

const  = await ..("/v1/policies/{id}");

Parameters, body and every documented response: GET /v1/policies/{id} in the HTTP reference.

PATCH /v1/policies/{id}

Update a policy rule. Cross-org ids return 404. Invalidates the per-org cache on success.

const  = await ..("/v1/policies/{id}", {
  : {
    : "policie_0000000000000000"
  },
  : {
    : "Example",
    : "deny",
    : [
      "string"
    ],
    : [
      "string"
    ],
    : true
  }
});

Parameters, body and every documented response: PATCH /v1/policies/{id} in the HTTP reference.

DELETE /v1/policies/{id}

Delete a policy rule. Cross-org ids return 404. Invalidates the per-org cache on success.

const  = await ..("/v1/policies/{id}", {
  : {
    : "policie_0000000000000000"
  }
});

Parameters, body and every documented response: DELETE /v1/policies/{id} in the HTTP reference.

Policies | CodeSpar