跳转到内容
EN

Create a publishable key

Code Mode: praxis.customer.publishableKeys.create

HTTP: POST /customer/v1/publishable_keys

Mint a publishable key so a page can admit anonymous visitors without you signing each one in from your backend. name labels the key for the console and the key list. resources is required and names what an anonymous visitor may reach, in the same form as the grant-code scopes: agent:<id>:chat, content:<id>:play or application:<id>:visit, with * for every object of one type; give it only what the anonymous experience needs, because any visitor who has the page can use the key. The response carries the plaintext key once, in key, and the store keeps only its hash — save it then, because no later call returns it. anon_rate_per_min, daily_session_cap and daily_spend_cap are optional limits of the key itself, all absent by default: the first caps how many exchanges the key allows per UTC minute across all visitors, the second how many new anonymous visitors it admits per UTC day (returning visitors are not counted); the third, daily_spend_cap, is the most the usage of this key’s visitors may cost in one UTC day, as an amount with its currency such as {“amount”: “5.00”, “currency”: “USD”} (at most 2 decimals), read from the key’s usage events; change them later with praxis.customer.publishableKeys.update. Returns HTTP 201; the exchange that consumes it is praxis.customer.accessTokens.create with publishable_key.

签名

praxis.customer.publishableKeys.create(args:{body:{/** Label for the key, shown in the console and the key list, for example Storefront. */ name:string;/** Resource scopes an anonymous visitor may reach, at least one, each a scope string or an object with scope and params; grant only what the anonymous experience n e.g. ["agent:agent_123:chat"] */ resources:Array<string|{/** Scope in the form <type>:<id>:<action>, where <id> may be * for every object of that type. e.g. "agent:agent_123:chat" */ scope:string;/** Product-defined data for this grant, for example an agent version or a budget. */ params?:Record<string,unknown>}>;/** Most exchanges of this key per UTC minute, from 1 to 100000, counting every visitor together; omit or send null for no per-key limit. */ anon_rate_per_min?:number|null;/** Most new anonymous visitors this key admits per UTC day, from 0 to 10000000; returning visitors are not counted. */ daily_session_cap?:number|null;/** The most the usage events of this key may cost in one UTC day, for example five dollars as amount 5.00 with currency USD; 0.00 closes the key. */ daily_spend_cap?:{/** Amount in major units of the currency as a decimal string with at most 2 decimals, for example 5.00 for five dollars; read back with exactly 2 decimals. e.g. "5.00" */ amount:string;/** Currency the amount is in, USD or CNY. e.g. "USD" */ currency:"USD"|"CNY"}|null}}):Promise<{/** Object type, always customer_publishable_key. */ type?:"customer_publishable_key";/** Key id (pk_…) used by the key list and the delete call. */ id?:string;/** Label you gave the key, for example Storefront. */ name?:string;/** The resource scopes the key grants an anonymous visitor. */ resources?:Array<{/** Scope in the form <type>:<id>:<action> — agent:<id>:chat, content:<id>:play or application:<id>:visit — where <id> may be * for every object of that type. e.g. "content:cnt_0123456789abcdef:play" */ scope?:string;/** Product-defined data for this grant, for example an agent version or a budget; this service stores it and never interprets it. */ params?:Record<string,unknown>}>;/** RFC 3339 time the key was created; the key list is ordered by it, newest first. */ created_at?:string;/** Most exchanges this key allows per UTC minute, counting every exchange (a returning visitor's too), or null for no per-key limit; the per-IP limit of the exchan */ anon_rate_per_min?:number|null;/** Most new anonymous visitors this key admits per UTC day, or null for no limit; a returning visitor that continues with its continuation_token is not counted, an */ daily_session_cap?:number|null;/** The most the usage events of this key may cost in one UTC day, or null for no spend cap; once reached, every visitor is refused until 00:00 UTC and a running pr */ daily_spend_cap?:{/** Amount in major units of the currency as a decimal string with at most 2 decimals, for example 5.00 for five dollars; read back with exactly 2 decimals. e.g. "5.00" */ amount:string;/** Currency the amount is in, USD or CNY. e.g. "USD" */ currency:"USD"|"CNY"}|null;/** The plaintext key value, present only in the create response; every later read returns the key without it, because only its hash is stored. */ key?:string}>;

请求体

必填内容类型说明
是application/jsonThe name of the key and the resource scopes it grants anonymous visitors.

响应

状态码内容类型说明
201application/jsonThe new key with its plaintext value, shown only in this response.
400application/jsonINVALID_PARAMS: the request is not shaped the way this face accepts — an unknown or misspelled field, a repeated query parameter, a resource scope not in the form <type>:<id>:<action>, an expand value that is not products, sign_ins or usage, or a confirm that does not repeat the path customer id. The error names the field at fault and what it accepts; correct that field and send the request again.
401application/jsonThe credential is missing, malformed or expired. Merchant routes answer UNAUTHENTICATED when the API key or session names no organization; the pre-auth doors answer GRANT_CODE_INVALID when a grant code is unknown, already used, expired or foreign, and ACCESS_TOKEN_EXPIRED when the end-user token cannot be verified (a sign-in that is over answers SIGN_IN_EXPIRED or SIGN_IN_REVOKED). Send a valid API key, request a fresh grant code, or sign the end user in again.
502application/jsonUPSTREAM_UNAVAILABLE: the token issuer or another dependency refused the call, so nothing was issued or changed. Retry later, and if it persists report the time and the request path.
503application/jsonUPSTREAM_UNAVAILABLE: this face is not usable in this environment — the CUSTOMER service binding is unwired, or the anonymous rate limiter is unavailable or misconfigured so the door fails closed. Use an environment where the face is wired, or retry when the dependency is back.