notdiamond 2.0.0-rc4 → 2.0.0

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.
Files changed (181) hide show
  1. package/CHANGELOG.md +164 -0
  2. package/LICENSE +1 -1
  3. package/README.md +294 -166
  4. package/client.d.mts +20 -23
  5. package/client.d.mts.map +1 -1
  6. package/client.d.ts +20 -23
  7. package/client.d.ts.map +1 -1
  8. package/client.js +43 -46
  9. package/client.js.map +1 -1
  10. package/client.mjs +41 -44
  11. package/client.mjs.map +1 -1
  12. package/core/api-promise.d.mts +2 -2
  13. package/core/api-promise.d.ts +2 -2
  14. package/core/error.d.mts +2 -2
  15. package/core/error.d.ts +2 -2
  16. package/core/error.js +4 -4
  17. package/core/error.mjs +2 -2
  18. package/core/resource.d.mts +3 -3
  19. package/core/resource.d.ts +3 -3
  20. package/index.d.mts +3 -3
  21. package/index.d.ts +3 -3
  22. package/index.js +4 -4
  23. package/index.mjs +3 -3
  24. package/internal/parse.d.mts +2 -2
  25. package/internal/parse.d.ts +2 -2
  26. package/internal/shims.js +1 -1
  27. package/internal/shims.mjs +1 -1
  28. package/internal/tslib.js +17 -17
  29. package/internal/uploads.d.mts +4 -4
  30. package/internal/uploads.d.ts +4 -4
  31. package/internal/utils/base64.js +2 -2
  32. package/internal/utils/base64.mjs +3 -3
  33. package/internal/utils/log.d.mts +3 -3
  34. package/internal/utils/log.d.ts +3 -3
  35. package/internal/utils/path.js +1 -1
  36. package/internal/utils/path.mjs +2 -2
  37. package/internal/utils/values.js +5 -5
  38. package/internal/utils/values.mjs +6 -6
  39. package/package.json +3 -3
  40. package/resources/{pzn.d.mts → custom-router.d.mts} +16 -96
  41. package/resources/custom-router.d.mts.map +1 -0
  42. package/resources/{pzn.d.ts → custom-router.d.ts} +16 -96
  43. package/resources/custom-router.d.ts.map +1 -0
  44. package/resources/{pzn.js → custom-router.js} +13 -50
  45. package/resources/custom-router.js.map +1 -0
  46. package/resources/{pzn.mjs → custom-router.mjs} +11 -48
  47. package/resources/custom-router.mjs.map +1 -0
  48. package/resources/index.d.mts +4 -5
  49. package/resources/index.d.mts.map +1 -1
  50. package/resources/index.d.ts +4 -5
  51. package/resources/index.d.ts.map +1 -1
  52. package/resources/index.js +5 -7
  53. package/resources/index.js.map +1 -1
  54. package/resources/index.mjs +2 -3
  55. package/resources/index.mjs.map +1 -1
  56. package/resources/model-router.d.mts +6 -123
  57. package/resources/model-router.d.mts.map +1 -1
  58. package/resources/model-router.d.ts +6 -123
  59. package/resources/model-router.d.ts.map +1 -1
  60. package/resources/model-router.js +3 -32
  61. package/resources/model-router.js.map +1 -1
  62. package/resources/model-router.mjs +3 -32
  63. package/resources/model-router.mjs.map +1 -1
  64. package/resources/preferences.d.mts +4 -23
  65. package/resources/preferences.d.mts.map +1 -1
  66. package/resources/preferences.d.ts +4 -23
  67. package/resources/preferences.d.ts.map +1 -1
  68. package/resources/preferences.js +3 -25
  69. package/resources/preferences.js.map +1 -1
  70. package/resources/preferences.mjs +3 -25
  71. package/resources/preferences.mjs.map +1 -1
  72. package/resources/prompt-adaptation.d.mts +684 -0
  73. package/resources/prompt-adaptation.d.mts.map +1 -0
  74. package/resources/prompt-adaptation.d.ts +684 -0
  75. package/resources/prompt-adaptation.d.ts.map +1 -0
  76. package/resources/prompt-adaptation.js +258 -0
  77. package/resources/prompt-adaptation.js.map +1 -0
  78. package/resources/prompt-adaptation.mjs +254 -0
  79. package/resources/prompt-adaptation.mjs.map +1 -0
  80. package/src/client.ts +49 -56
  81. package/src/core/api-promise.ts +4 -4
  82. package/src/core/error.ts +2 -2
  83. package/src/core/resource.ts +3 -3
  84. package/src/index.ts +3 -3
  85. package/src/internal/parse.ts +2 -2
  86. package/src/internal/shims.ts +1 -1
  87. package/src/internal/uploads.ts +5 -5
  88. package/src/internal/utils/base64.ts +3 -3
  89. package/src/internal/utils/log.ts +3 -3
  90. package/src/internal/utils/path.ts +2 -2
  91. package/src/internal/utils/values.ts +6 -6
  92. package/src/resources/{pzn.ts → custom-router.ts} +17 -122
  93. package/src/resources/index.ts +14 -16
  94. package/src/resources/model-router.ts +5 -139
  95. package/src/resources/preferences.ts +3 -34
  96. package/src/resources/prompt-adaptation.ts +777 -0
  97. package/src/version.ts +1 -1
  98. package/version.d.mts +1 -1
  99. package/version.d.mts.map +1 -1
  100. package/version.d.ts +1 -1
  101. package/version.d.ts.map +1 -1
  102. package/version.js +1 -1
  103. package/version.js.map +1 -1
  104. package/version.mjs +1 -1
  105. package/version.mjs.map +1 -1
  106. package/resources/prompt/adapt.d.mts +0 -352
  107. package/resources/prompt/adapt.d.mts.map +0 -1
  108. package/resources/prompt/adapt.d.ts +0 -352
  109. package/resources/prompt/adapt.d.ts.map +0 -1
  110. package/resources/prompt/adapt.js +0 -154
  111. package/resources/prompt/adapt.js.map +0 -1
  112. package/resources/prompt/adapt.mjs +0 -150
  113. package/resources/prompt/adapt.mjs.map +0 -1
  114. package/resources/prompt/index.d.mts +0 -3
  115. package/resources/prompt/index.d.mts.map +0 -1
  116. package/resources/prompt/index.d.ts +0 -3
  117. package/resources/prompt/index.d.ts.map +0 -1
  118. package/resources/prompt/index.js +0 -9
  119. package/resources/prompt/index.js.map +0 -1
  120. package/resources/prompt/index.mjs +0 -4
  121. package/resources/prompt/index.mjs.map +0 -1
  122. package/resources/prompt/prompt.d.mts +0 -338
  123. package/resources/prompt/prompt.d.mts.map +0 -1
  124. package/resources/prompt/prompt.d.ts +0 -338
  125. package/resources/prompt/prompt.d.ts.map +0 -1
  126. package/resources/prompt/prompt.js +0 -128
  127. package/resources/prompt/prompt.js.map +0 -1
  128. package/resources/prompt/prompt.mjs +0 -123
  129. package/resources/prompt/prompt.mjs.map +0 -1
  130. package/resources/prompt.d.mts +0 -2
  131. package/resources/prompt.d.mts.map +0 -1
  132. package/resources/prompt.d.ts +0 -2
  133. package/resources/prompt.d.ts.map +0 -1
  134. package/resources/prompt.js +0 -6
  135. package/resources/prompt.js.map +0 -1
  136. package/resources/prompt.mjs +0 -3
  137. package/resources/prompt.mjs.map +0 -1
  138. package/resources/pzn.d.mts.map +0 -1
  139. package/resources/pzn.d.ts.map +0 -1
  140. package/resources/pzn.js.map +0 -1
  141. package/resources/pzn.mjs.map +0 -1
  142. package/resources/report/index.d.mts +0 -3
  143. package/resources/report/index.d.mts.map +0 -1
  144. package/resources/report/index.d.ts +0 -3
  145. package/resources/report/index.d.ts.map +0 -1
  146. package/resources/report/index.js +0 -9
  147. package/resources/report/index.js.map +0 -1
  148. package/resources/report/index.mjs +0 -4
  149. package/resources/report/index.mjs.map +0 -1
  150. package/resources/report/metrics.d.mts +0 -87
  151. package/resources/report/metrics.d.mts.map +0 -1
  152. package/resources/report/metrics.d.ts +0 -87
  153. package/resources/report/metrics.d.ts.map +0 -1
  154. package/resources/report/metrics.js +0 -57
  155. package/resources/report/metrics.js.map +0 -1
  156. package/resources/report/metrics.mjs +0 -53
  157. package/resources/report/metrics.mjs.map +0 -1
  158. package/resources/report/report.d.mts +0 -10
  159. package/resources/report/report.d.mts.map +0 -1
  160. package/resources/report/report.d.ts +0 -10
  161. package/resources/report/report.d.ts.map +0 -1
  162. package/resources/report/report.js +0 -17
  163. package/resources/report/report.js.map +0 -1
  164. package/resources/report/report.mjs +0 -12
  165. package/resources/report/report.mjs.map +0 -1
  166. package/resources/report.d.mts +0 -2
  167. package/resources/report.d.mts.map +0 -1
  168. package/resources/report.d.ts +0 -2
  169. package/resources/report.d.ts.map +0 -1
  170. package/resources/report.js +0 -6
  171. package/resources/report.js.map +0 -1
  172. package/resources/report.mjs +0 -3
  173. package/resources/report.mjs.map +0 -1
  174. package/src/resources/prompt/adapt.ts +0 -402
  175. package/src/resources/prompt/index.ts +0 -16
  176. package/src/resources/prompt/prompt.ts +0 -398
  177. package/src/resources/prompt.ts +0 -3
  178. package/src/resources/report/index.ts +0 -4
  179. package/src/resources/report/metrics.ts +0 -99
  180. package/src/resources/report/report.ts +0 -19
  181. package/src/resources/report.ts +0 -3
@@ -0,0 +1,777 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from '../core/resource';
4
+ import * as PromptAdaptationAPI from './prompt-adaptation';
5
+ import { APIPromise } from '../core/api-promise';
6
+ import { RequestOptions } from '../internal/request-options';
7
+ import { path } from '../internal/utils/path';
8
+
9
+ export class PromptAdaptation extends APIResource {
10
+ /**
11
+ * Adapt your prompt from one LLM to work optimally across different target LLMs.
12
+ *
13
+ * This endpoint automatically optimizes your prompt (system prompt + user message
14
+ * template) to improve accuracy on your use case across various models. Each model
15
+ * has unique characteristics, and what works well for GPT-5 might not work as well
16
+ * for Claude or Gemini.
17
+ *
18
+ * **How Prompt Adaptation Works:**
19
+ *
20
+ * 1. You provide your current prompt and optionally your current origin model
21
+ * 2. You specify the target models you want to adapt your prompt to
22
+ * 3. You provide evaluation examples (golden records) with expected answers
23
+ * 4. The system runs optimization to find the best prompt for each target model
24
+ * 5. You receive adapted prompts that perform well on your target models
25
+ *
26
+ * **Evaluation Metrics:** Choose either a standard metric or provide custom
27
+ * evaluation:
28
+ *
29
+ * - **Standard metrics**: LLMaaJ:Sem_Sim_1 (semantic similarity), JSON_Match
30
+ * - **Custom evaluation**: Provide evaluation_config with your own LLM judge,
31
+ * prompt, and cutoff
32
+ *
33
+ * **Dataset Requirements:**
34
+ *
35
+ * - Minimum 25 examples in train_goldens (more examples = better adaptation)
36
+ * - **Prototype mode**: Set `prototype_mode: true` to use as few as 3 examples for
37
+ * prototyping
38
+ * - Recommended when you don't have enough data yet to build a proof-of-concept
39
+ * - Note: Performance may be degraded compared to standard mode (25+ examples)
40
+ * - Trade-off: Faster iteration with less data vs. potentially less
41
+ * generalizability
42
+ * - Each example must have fields matching your template placeholders
43
+ * - Supervised evaluation requires 'answer' field in each golden record
44
+ * - Unsupervised evaluation can work without answers
45
+ *
46
+ * **Training Time:**
47
+ *
48
+ * - Processing is asynchronous and typically takes 10-30 minutes
49
+ * - Time depends on: number of target models, dataset size, model availability
50
+ * - Use the returned adaptation_run_id to check status and retrieve results
51
+ *
52
+ * **Example Workflow:**
53
+ *
54
+ * ```
55
+ * 1. POST /v2/prompt/adapt - Submit adaptation request
56
+ * 2. GET /v2/prompt/adaptStatus/{id} - Poll status until completed
57
+ * 3. GET /v2/prompt/adaptResults/{id} - Retrieve optimized prompts
58
+ * 4. Use optimized prompts in production with target models
59
+ * ```
60
+ *
61
+ * **Related Documentation:** See
62
+ * https://docs.notdiamond.ai/docs/adapting-prompts-to-new-models for detailed
63
+ * guide.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * const response = await client.promptAdaptation.adapt({
68
+ * fields: ['question'],
69
+ * system_prompt: 'You are a mathematical assistant that counts digits accurately.',
70
+ * target_models: [
71
+ * { model: 'claude-sonnet-4-5-20250929', provider: 'anthropic' },
72
+ * { model: 'gemini-2.5-flash', provider: 'google' },
73
+ * ],
74
+ * template: 'Question: {question}\nAnswer:',
75
+ * evaluation_metric: 'LLMaaJ:Sem_Sim_1',
76
+ * prototype_mode: true,
77
+ * test_goldens: [
78
+ * {
79
+ * fields: { ... },
80
+ * answer: '15',
81
+ * },
82
+ * {
83
+ * fields: { ... },
84
+ * answer: '8',
85
+ * },
86
+ * {
87
+ * fields: { ... },
88
+ * answer: '1',
89
+ * },
90
+ * {
91
+ * fields: { ... },
92
+ * answer: '10',
93
+ * },
94
+ * {
95
+ * fields: { ... },
96
+ * answer: '11',
97
+ * },
98
+ * ],
99
+ * train_goldens: [
100
+ * {
101
+ * fields: { ... },
102
+ * answer: '20',
103
+ * },
104
+ * {
105
+ * fields: { ... },
106
+ * answer: '10',
107
+ * },
108
+ * {
109
+ * fields: { ... },
110
+ * answer: '0',
111
+ * },
112
+ * {
113
+ * fields: { ... },
114
+ * answer: '16',
115
+ * },
116
+ * {
117
+ * fields: { ... },
118
+ * answer: '2',
119
+ * },
120
+ * ],
121
+ * });
122
+ * ```
123
+ */
124
+ adapt(
125
+ body: PromptAdaptationAdaptParams,
126
+ options?: RequestOptions,
127
+ ): APIPromise<PromptAdaptationAdaptResponse> {
128
+ return this._client.post('/v2/prompt/adapt', { body, ...options });
129
+ }
130
+
131
+ /**
132
+ * Retrieve the complete results of a prompt adaptation run, including optimized
133
+ * prompts for all target models.
134
+ *
135
+ * This endpoint returns the adapted prompts and evaluation metrics for each target
136
+ * model in your adaptation request. Call this endpoint after the adaptation status
137
+ * is 'completed' to get your optimized prompts.
138
+ *
139
+ * **Response Structure:**
140
+ *
141
+ * - **origin_model**: Baseline performance of your original prompt on the origin
142
+ * model
143
+ * - Includes: system_prompt, user_message_template, score, evaluation metrics,
144
+ * cost
145
+ * - **target_models**: Array of results for each target model
146
+ * - Includes: optimized system_prompt, user_message_template, template_fields
147
+ * - pre_optimization_score: Performance before adaptation
148
+ * - post_optimization_score: Performance after adaptation
149
+ * - Evaluation metrics and cost information
150
+ *
151
+ * **Using Adapted Prompts:**
152
+ *
153
+ * 1. Extract the `system_prompt` and `user_message_template` from each target
154
+ * model result
155
+ * 2. Use `user_message_template_fields` to know which fields to substitute
156
+ * 3. Apply the optimized prompts when calling the respective target models
157
+ * 4. Compare pre/post optimization scores to see improvement
158
+ *
159
+ * **Status Handling:**
160
+ *
161
+ * - If adaptation is still processing, target model results will have
162
+ * `result_status: "processing"`
163
+ * - Only completed target models will have system_prompt and template values
164
+ * - Failed target models will have `result_status: "failed"` with null values
165
+ *
166
+ * **Cost Information:**
167
+ *
168
+ * - Each model result includes cost in USD for the adaptation process
169
+ * - Costs vary based on model pricing and number of evaluation examples
170
+ * - Typical range: $0.10 - $2.00 per target model
171
+ *
172
+ * **Best Practices:**
173
+ *
174
+ * 1. Wait for status 'completed' before calling this endpoint
175
+ * 2. Check result_status for each target model
176
+ * 3. Validate that post_optimization_score > pre_optimization_score
177
+ * 4. Save optimized prompts for production use
178
+ * 5. A/B test adapted prompts against originals in production
179
+ *
180
+ * @example
181
+ * ```ts
182
+ * const response =
183
+ * await client.promptAdaptation.getAdaptResults(
184
+ * 'adaptation_run_id',
185
+ * );
186
+ * ```
187
+ */
188
+ getAdaptResults(
189
+ adaptationRunID: string,
190
+ options?: RequestOptions,
191
+ ): APIPromise<PromptAdaptationGetAdaptResultsResponse> {
192
+ return this._client.get(path`/v2/prompt/adaptResults/${adaptationRunID}`, options);
193
+ }
194
+
195
+ /**
196
+ * Check the status of a prompt adaptation run.
197
+ *
198
+ * Use this endpoint to poll the status of your adaptation request. Processing is
199
+ * asynchronous, so you'll need to check periodically until the status indicates
200
+ * completion.
201
+ *
202
+ * **Status Values:**
203
+ *
204
+ * - `created`: Initial state, not yet processing
205
+ * - `queued`: Waiting for processing capacity (check queue_position)
206
+ * - `processing`: Currently optimizing prompts
207
+ * - `completed`: All target models have been processed successfully
208
+ * - `failed`: One or more target models failed to process
209
+ *
210
+ * **Polling Recommendations:**
211
+ *
212
+ * - Poll every 30-60 seconds during processing
213
+ * - Check queue_position if status is 'queued' to estimate wait time
214
+ * - Stop polling once status is 'completed' or 'failed'
215
+ * - Use GET /v2/prompt/adaptResults to retrieve results after completion
216
+ *
217
+ * **Queue Position:**
218
+ *
219
+ * - Only present when status is 'queued'
220
+ * - Lower numbers mean earlier processing (position 1 is next)
221
+ * - Typical wait time: 1-5 minutes per position
222
+ *
223
+ * **Note:** This endpoint only returns status information. To get the actual
224
+ * adapted prompts and evaluation results, use GET /v2/prompt/adaptResults once
225
+ * status is 'completed'.
226
+ *
227
+ * @example
228
+ * ```ts
229
+ * const response =
230
+ * await client.promptAdaptation.getAdaptStatus(
231
+ * 'adaptation_run_id',
232
+ * );
233
+ * ```
234
+ */
235
+ getAdaptStatus(
236
+ adaptationRunID: string,
237
+ options?: RequestOptions,
238
+ ): APIPromise<PromptAdaptationGetAdaptStatusResponse> {
239
+ return this._client.get(path`/v2/prompt/adaptStatus/${adaptationRunID}`, options);
240
+ }
241
+
242
+ /**
243
+ * Get LLM usage costs for a specific prompt adaptation run.
244
+ *
245
+ * This endpoint returns the total cost and detailed usage records for all LLM
246
+ * requests made during a prompt adaptation run. Use this to track costs associated
247
+ * with optimizing prompts for different target models.
248
+ *
249
+ * **Cost Breakdown:**
250
+ *
251
+ * - Total cost across all models used in the adaptation
252
+ * - Individual usage records with provider, model, tokens, and costs
253
+ * - Timestamps for each LLM request
254
+ *
255
+ * **Access Control:**
256
+ *
257
+ * - Only accessible by the user who created the adaptation run
258
+ * - Requires prompt adaptation access
259
+ *
260
+ * @example
261
+ * ```ts
262
+ * const response = await client.promptAdaptation.getCost(
263
+ * 'adaptation_run_id',
264
+ * );
265
+ * ```
266
+ */
267
+ getCost(adaptationRunID: string, options?: RequestOptions): APIPromise<PromptAdaptationGetCostResponse> {
268
+ return this._client.get(path`/v2/prompt/adapt/${adaptationRunID}/costs`, options);
269
+ }
270
+ }
271
+
272
+ /**
273
+ * A training or test example for prompt adaptation.
274
+ */
275
+ export interface GoldenRecord {
276
+ /**
277
+ * Dictionary mapping field names to their values. Keys must match the fields
278
+ * specified in the template
279
+ */
280
+ fields: { [key: string]: string };
281
+
282
+ /**
283
+ * Expected answer for supervised evaluation. Required for supervised metrics,
284
+ * optional for unsupervised
285
+ */
286
+ answer?: string | null;
287
+ }
288
+
289
+ /**
290
+ * Status enum for asynchronous jobs (prompt adaptation, custom router training,
291
+ * etc.).
292
+ *
293
+ * Represents the current state of a long-running operation:
294
+ *
295
+ * - **created**: Job has been initialized but not yet queued
296
+ * - **queued**: Job is waiting in the queue to be processed
297
+ * - **processing**: Job is currently being executed
298
+ * - **completed**: Job finished successfully and results are available
299
+ * - **failed**: Job encountered an error and did not complete
300
+ */
301
+ export type JobStatus = 'created' | 'queued' | 'processing' | 'completed' | 'failed';
302
+
303
+ /**
304
+ * Model for specifying an LLM provider in API requests.
305
+ */
306
+ export interface RequestProvider {
307
+ /**
308
+ * Model name (e.g., 'gpt-4o', 'claude-sonnet-4-5-20250929')
309
+ */
310
+ model: string;
311
+
312
+ /**
313
+ * Provider name (e.g., 'openai', 'anthropic', 'google')
314
+ */
315
+ provider: string;
316
+
317
+ /**
318
+ * Maximum context length for the model (required for custom models)
319
+ */
320
+ context_length?: number | null;
321
+
322
+ /**
323
+ * Input token price per million tokens in USD (required for custom models)
324
+ */
325
+ input_price?: number | null;
326
+
327
+ /**
328
+ * Whether this is a custom model not in Not Diamond's supported model list
329
+ */
330
+ is_custom?: boolean;
331
+
332
+ /**
333
+ * Average latency in seconds (required for custom models)
334
+ */
335
+ latency?: number | null;
336
+
337
+ /**
338
+ * Output token price per million tokens in USD (required for custom models)
339
+ */
340
+ output_price?: number | null;
341
+ }
342
+
343
+ /**
344
+ * Response model for POST /v2/prompt/adapt endpoint.
345
+ *
346
+ * Returned immediately after submitting a prompt adaptation request. The
347
+ * adaptation process runs asynchronously, so use the returned adaptation_run_id to
348
+ * track progress and retrieve results when complete.
349
+ *
350
+ * **Next steps:**
351
+ *
352
+ * 1. Store the adaptation_run_id
353
+ * 2. Poll GET /v2/prompt/adaptStatus/{adaptation_run_id} to check progress
354
+ * 3. When status is 'completed', retrieve optimized prompts from GET
355
+ * /v2/prompt/adaptResults/{adaptation_run_id}
356
+ * 4. Use the optimized prompts with your target models
357
+ */
358
+ export interface PromptAdaptationAdaptResponse {
359
+ /**
360
+ * Unique identifier for this adaptation run. Use this to poll status and retrieve
361
+ * optimized prompts when complete
362
+ */
363
+ adaptation_run_id: string;
364
+ }
365
+
366
+ /**
367
+ * Response model for GET /v2/prompt/adaptResults/{adaptation_run_id} endpoint.
368
+ *
369
+ * Contains the complete results of a prompt adaptation run, including optimized
370
+ * prompts and evaluation metrics for all target models. Use this to retrieve your
371
+ * adapted prompts after the adaptation status is 'completed'.
372
+ *
373
+ * The response includes:
374
+ *
375
+ * - Baseline performance of your original prompt on the origin model
376
+ * - Optimized prompts for each target model with pre/post optimization scores
377
+ * - Evaluation metrics and cost information for each model
378
+ */
379
+ export interface PromptAdaptationGetAdaptResultsResponse {
380
+ /**
381
+ * Unique ID for this adaptation run
382
+ */
383
+ id: string;
384
+
385
+ /**
386
+ * Timestamp when this adaptation run was created
387
+ */
388
+ created_at: string;
389
+
390
+ /**
391
+ * Overall status of the adaptation run (queued, running, completed, failed)
392
+ */
393
+ job_status: JobStatus;
394
+
395
+ /**
396
+ * Results for each target model with optimized prompts and improvement scores
397
+ */
398
+ target_models: Array<PromptAdaptationGetAdaptResultsResponse.TargetModel>;
399
+
400
+ /**
401
+ * Timestamp of last update to this adaptation run
402
+ */
403
+ updated_at: string | null;
404
+
405
+ evaluation_config?: string | null;
406
+
407
+ evaluation_metric?: string | null;
408
+
409
+ /**
410
+ * Metrics for the LLM requests made during the adaptation run (e.g.,
411
+ * total_requests, avg_latency)
412
+ */
413
+ llm_request_metrics?: { [key: string]: number };
414
+
415
+ /**
416
+ * Baseline results for the origin model in prompt adaptation.
417
+ *
418
+ * Part of AdaptationRunResultsResponse. Contains the performance metrics and
419
+ * prompt configuration for your original prompt on the origin model. This serves
420
+ * as the baseline to compare against optimized prompts for target models.
421
+ *
422
+ * **Fields include:**
423
+ *
424
+ * - Original system prompt and user message template
425
+ * - Baseline performance score and evaluation metrics
426
+ * - Cost of running the baseline evaluation
427
+ * - Job status for the origin model evaluation
428
+ */
429
+ origin_model?: PromptAdaptationGetAdaptResultsResponse.OriginModel | null;
430
+
431
+ /**
432
+ * Whether this adaptation run was created with prototype mode (3-24 training
433
+ * examples allowed). Prototype mode may have degraded performance compared to
434
+ * standard mode (25+ examples)
435
+ */
436
+ prototype_mode?: boolean;
437
+ }
438
+
439
+ export namespace PromptAdaptationGetAdaptResultsResponse {
440
+ /**
441
+ * Optimized prompt results for a single target model in prompt adaptation.
442
+ *
443
+ * Part of AdaptationRunResultsResponse. Contains the optimized system prompt and
444
+ * user message template for a specific target model, along with performance scores
445
+ * before and after optimization. Use these optimized prompts with the target model
446
+ * to achieve better performance than the original prompt.
447
+ *
448
+ * **Key metrics:**
449
+ *
450
+ * - **pre_optimization_score**: Performance with original prompt on this target
451
+ * model
452
+ * - **post_optimization_score**: Performance with optimized prompt on this target
453
+ * model
454
+ * - **Score improvement**: post - pre shows how much optimization helped
455
+ *
456
+ * **Usage:**
457
+ *
458
+ * 1. Extract the optimized system_prompt and user_message_template
459
+ * 2. Replace placeholders in user_message_template using fields from your data
460
+ * 3. Use these prompts when calling this target model
461
+ * 4. Compare pre/post scores to see improvement gained
462
+ */
463
+ export interface TargetModel {
464
+ cost: number | null;
465
+
466
+ model_name: string;
467
+
468
+ post_optimization_evals: { [key: string]: unknown } | null;
469
+
470
+ post_optimization_score: number | null;
471
+
472
+ pre_optimization_evals: { [key: string]: unknown } | null;
473
+
474
+ pre_optimization_score: number | null;
475
+
476
+ task_type: string | null;
477
+
478
+ /**
479
+ * Status enum for asynchronous jobs (prompt adaptation, custom router training,
480
+ * etc.).
481
+ *
482
+ * Represents the current state of a long-running operation:
483
+ *
484
+ * - **created**: Job has been initialized but not yet queued
485
+ * - **queued**: Job is waiting in the queue to be processed
486
+ * - **processing**: Job is currently being executed
487
+ * - **completed**: Job finished successfully and results are available
488
+ * - **failed**: Job encountered an error and did not complete
489
+ */
490
+ result_status?: PromptAdaptationAPI.JobStatus | null;
491
+
492
+ /**
493
+ * Optimized system prompt for this target model. Use this as the system message in
494
+ * your LLM calls
495
+ */
496
+ system_prompt?: string | null;
497
+
498
+ /**
499
+ * Optimized user message template with placeholders. Substitute fields using your
500
+ * data before calling the LLM
501
+ */
502
+ user_message_template?: string | null;
503
+
504
+ /**
505
+ * List of field names to substitute in the template (e.g., ['question',
506
+ * 'context']). These match the curly-brace placeholders in user_message_template
507
+ */
508
+ user_message_template_fields?: Array<string> | null;
509
+ }
510
+
511
+ /**
512
+ * Baseline results for the origin model in prompt adaptation.
513
+ *
514
+ * Part of AdaptationRunResultsResponse. Contains the performance metrics and
515
+ * prompt configuration for your original prompt on the origin model. This serves
516
+ * as the baseline to compare against optimized prompts for target models.
517
+ *
518
+ * **Fields include:**
519
+ *
520
+ * - Original system prompt and user message template
521
+ * - Baseline performance score and evaluation metrics
522
+ * - Cost of running the baseline evaluation
523
+ * - Job status for the origin model evaluation
524
+ */
525
+ export interface OriginModel {
526
+ cost: number | null;
527
+
528
+ evals: { [key: string]: unknown } | null;
529
+
530
+ model_name: string | null;
531
+
532
+ score: number | null;
533
+
534
+ /**
535
+ * Status enum for asynchronous jobs (prompt adaptation, custom router training,
536
+ * etc.).
537
+ *
538
+ * Represents the current state of a long-running operation:
539
+ *
540
+ * - **created**: Job has been initialized but not yet queued
541
+ * - **queued**: Job is waiting in the queue to be processed
542
+ * - **processing**: Job is currently being executed
543
+ * - **completed**: Job finished successfully and results are available
544
+ * - **failed**: Job encountered an error and did not complete
545
+ */
546
+ result_status?: PromptAdaptationAPI.JobStatus | null;
547
+
548
+ /**
549
+ * Original system prompt used for the origin model
550
+ */
551
+ system_prompt?: string | null;
552
+
553
+ /**
554
+ * Original user message template used for the origin model
555
+ */
556
+ user_message_template?: string | null;
557
+ }
558
+ }
559
+
560
+ /**
561
+ * Response model for GET /v2/prompt/adaptStatus/{adaptation_run_id} endpoint.
562
+ *
563
+ * Returns the current status of an asynchronous prompt adaptation job. Poll this
564
+ * endpoint periodically to track progress. When status is 'completed', you can
565
+ * retrieve the optimized prompts using the /adaptResults endpoint.
566
+ *
567
+ * **Status values:**
568
+ *
569
+ * - **created**: Job has been initialized
570
+ * - **queued**: Waiting in queue (check queue_position for your place in line)
571
+ * - **processing**: Currently running optimization
572
+ * - **completed**: Finished successfully, results available via /adaptResults
573
+ * - **failed**: Encountered an error during processing
574
+ *
575
+ * **Polling recommendations:**
576
+ *
577
+ * - Poll every 30-60 seconds while status is incomplete
578
+ * - Stop polling once status is 'completed' or 'failed'
579
+ * - Adaptation typically takes 10-30 minutes total
580
+ */
581
+ export interface PromptAdaptationGetAdaptStatusResponse {
582
+ /**
583
+ * Unique identifier for this adaptation run. Use this to poll status and retrieve
584
+ * optimized prompts when complete
585
+ */
586
+ adaptation_run_id: string;
587
+
588
+ /**
589
+ * Current status of the adaptation run. Poll until this is 'completed' or 'failed'
590
+ */
591
+ status: JobStatus;
592
+
593
+ /**
594
+ * Position in queue when status is 'queued'. Lower numbers process sooner. Null
595
+ * when not queued
596
+ */
597
+ queue_position?: number | null;
598
+ }
599
+
600
+ /**
601
+ * Response model for GET /v2/prompt/adapt/{adaptation_run_id}/costs endpoint.
602
+ *
603
+ * Contains the total LLM costs and detailed usage records for a prompt adaptation
604
+ * run. Use this to track costs associated with optimizing prompts for different
605
+ * target models.
606
+ */
607
+ export interface PromptAdaptationGetCostResponse {
608
+ /**
609
+ * Unique identifier for the adaptation run
610
+ */
611
+ adaptation_run_id: string;
612
+
613
+ /**
614
+ * Total cost in USD across all LLM requests in this adaptation run
615
+ */
616
+ total_cost: number;
617
+
618
+ /**
619
+ * Detailed usage records for each LLM request made during the adaptation
620
+ */
621
+ usage_records: Array<PromptAdaptationGetCostResponse.UsageRecord>;
622
+ }
623
+
624
+ export namespace PromptAdaptationGetCostResponse {
625
+ /**
626
+ * Individual LLM usage record with token counts and cost breakdown.
627
+ *
628
+ * Returned by GET /llm-usage endpoint and included in AdaptationRunCostResponse.
629
+ * Each record represents a single LLM API call with detailed usage metrics.
630
+ */
631
+ export interface UsageRecord {
632
+ /**
633
+ * Unique identifier for this usage record
634
+ */
635
+ id: string;
636
+
637
+ /**
638
+ * Adaptation run ID this usage is associated with
639
+ */
640
+ adaptation_run_id: string;
641
+
642
+ /**
643
+ * Cost of input tokens in USD
644
+ */
645
+ input_cost: number;
646
+
647
+ /**
648
+ * Number of input tokens consumed
649
+ */
650
+ input_tokens: number;
651
+
652
+ /**
653
+ * Model name (e.g., 'gpt-4', 'claude-3-opus-20240229')
654
+ */
655
+ model: string;
656
+
657
+ /**
658
+ * Organization ID associated with the request
659
+ */
660
+ organization_id: string;
661
+
662
+ /**
663
+ * Cost of output tokens in USD
664
+ */
665
+ output_cost: number;
666
+
667
+ /**
668
+ * Number of output tokens generated
669
+ */
670
+ output_tokens: number;
671
+
672
+ /**
673
+ * LLM provider (e.g., 'openai', 'anthropic', 'google')
674
+ */
675
+ provider: string;
676
+
677
+ /**
678
+ * Type of task: 'pre-optimization evaluation', 'optimization', or
679
+ * 'post-optimization evaluation'
680
+ */
681
+ task_type: string;
682
+
683
+ /**
684
+ * Unix timestamp when the request was made
685
+ */
686
+ timestamp: number;
687
+
688
+ /**
689
+ * Total cost (input + output) in USD
690
+ */
691
+ total_cost: number;
692
+
693
+ /**
694
+ * User ID who made the request
695
+ */
696
+ user_id: string;
697
+ }
698
+ }
699
+
700
+ export interface PromptAdaptationAdaptParams {
701
+ /**
702
+ * List of field names that will be substituted into the template. Must match keys
703
+ * in golden records
704
+ */
705
+ fields: Array<string>;
706
+
707
+ /**
708
+ * System prompt to use with the origin model. This sets the context and role for
709
+ * the LLM
710
+ */
711
+ system_prompt: string;
712
+
713
+ /**
714
+ * List of models to adapt the prompt for. Maximum count depends on your
715
+ * subscription tier (Free: 1, Starter: 3, Startup: 5, Enterprise: 10)
716
+ */
717
+ target_models: Array<RequestProvider>;
718
+
719
+ /**
720
+ * User message template with placeholders for fields. Use curly braces for field
721
+ * substitution
722
+ */
723
+ template: string;
724
+
725
+ evaluation_config?: string | null;
726
+
727
+ evaluation_metric?: string | null;
728
+
729
+ /**
730
+ * Training examples (legacy parameter). Use train_goldens and test_goldens for
731
+ * better control. Minimum 25 examples (or 3 with prototype_mode=true)
732
+ */
733
+ goldens?: Array<GoldenRecord> | null;
734
+
735
+ /**
736
+ * Model for specifying an LLM provider in API requests.
737
+ */
738
+ origin_model?: RequestProvider | null;
739
+
740
+ /**
741
+ * Optional baseline score for the origin model. If provided, can skip origin model
742
+ * evaluation
743
+ */
744
+ origin_model_evaluation_score?: number | null;
745
+
746
+ /**
747
+ * Enable prototype mode to use as few as 3 training examples (instead of 25).
748
+ * Note: Performance may be degraded with fewer examples. Recommended for
749
+ * prototyping AI applications when you don't have enough data yet
750
+ */
751
+ prototype_mode?: boolean;
752
+
753
+ /**
754
+ * Test examples for evaluation. Required if train_goldens is provided. Used to
755
+ * measure final performance on held-out data
756
+ */
757
+ test_goldens?: Array<GoldenRecord> | null;
758
+
759
+ /**
760
+ * Training examples for prompt optimization. Minimum 25 examples required (or 3
761
+ * with prototype_mode=true). Cannot be used with 'goldens' parameter
762
+ */
763
+ train_goldens?: Array<GoldenRecord> | null;
764
+ }
765
+
766
+ export declare namespace PromptAdaptation {
767
+ export {
768
+ type GoldenRecord as GoldenRecord,
769
+ type JobStatus as JobStatus,
770
+ type RequestProvider as RequestProvider,
771
+ type PromptAdaptationAdaptResponse as PromptAdaptationAdaptResponse,
772
+ type PromptAdaptationGetAdaptResultsResponse as PromptAdaptationGetAdaptResultsResponse,
773
+ type PromptAdaptationGetAdaptStatusResponse as PromptAdaptationGetAdaptStatusResponse,
774
+ type PromptAdaptationGetCostResponse as PromptAdaptationGetCostResponse,
775
+ type PromptAdaptationAdaptParams as PromptAdaptationAdaptParams,
776
+ };
777
+ }