@402flow/sdk 0.1.0-alpha.22 → 0.1.0-alpha.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -132,6 +132,46 @@ If the merchant does not require payment for that exact request, the SDK returns
132
132
 
133
133
  `result.response` is always the merchant HTTP response. SDK-owned payment metadata such as `paidRequestId`, `paymentAttemptId`, `receiptId`, and `receipt` stays on the SDK result instead of being injected into the merchant JSON body.
134
134
 
135
+ ### Optional Attribution
136
+
137
+ Most SDK users do not need to send attribution at all.
138
+
139
+ The optional `attribution` field is for callers that already know where this paid endpoint came from and want that provenance to survive into control-plane audit, reporting, and later policy analysis.
140
+
141
+ Common cases:
142
+
143
+ 1. your app found the endpoint through your own registry or catalog
144
+ 2. your app imported the endpoint from a saved workspace config
145
+ 3. your agent is calling a merchant directly and you want to mark that path as `direct`
146
+ 4. your host selected the endpoint from a discovery surface such as Bazaar, Dexter, pay.sh, x402scan, or another catalog
147
+
148
+ This field does not make payment execution work. It improves lifecycle explainability.
149
+
150
+ If you do not already know the endpoint provenance, omit it.
151
+
152
+ ```ts
153
+ const result = await client.fetchPaid(
154
+ 'https://merchant.example.com/reports/daily',
155
+ {
156
+ method: 'POST',
157
+ headers: {
158
+ 'content-type': 'application/json',
159
+ },
160
+ body: createJsonRequestBody({
161
+ date: '2026-03-25',
162
+ }),
163
+ },
164
+ {
165
+ description: 'sync daily paid report',
166
+ attribution: {
167
+ discoverySource: 'direct',
168
+ },
169
+ },
170
+ );
171
+ ```
172
+
173
+ For the first attribution slice, `discoverySource` is the main field callers should set when they have a clear answer. The control plane derives an early endpoint-level `resourceIdentity` from the request method and URL, so callers do not need to compute that themselves.
174
+
135
175
  ### Interpreting Merchant Responses
136
176
 
137
177
  The SDK gives you a stable place for payment metadata, but it does not invent a universal fulfilled-response schema for merchant content.
@@ -228,6 +268,13 @@ const prepared = await client.preparePaidRequest(
228
268
 
229
269
  `externalMetadata` is optional caller context. It improves preparation when the caller already has structured endpoint knowledge, but it is not required for normal SDK use.
230
270
 
271
+ `attribution` is separate from `externalMetadata`.
272
+
273
+ 1. `externalMetadata` helps the SDK understand request shape before execution
274
+ 2. `attribution` helps the control plane explain where the paid endpoint came from after execution
275
+
276
+ Use `externalMetadata` for request hints. Use `attribution` for provenance. Either may be omitted.
277
+
231
278
  ### What `ready` Means
232
279
 
233
280
  `ready` means this exact request can proceed through governed paid execution as-is; it does not mean the SDK has inferred the best task parameters for you.
@@ -256,6 +303,13 @@ const prepared = await client.preparePaidRequest(
256
303
  prompt: 'foggy coastline',
257
304
  }),
258
305
  },
306
+
307
+ const result = await client.executePreparedRequest(prepared, {
308
+ description: 'generate paid image',
309
+ attribution: {
310
+ discoverySource: 'manual',
311
+ },
312
+ });
259
313
  );
260
314
 
261
315
  if (prepared.kind === 'ready') {