notdiamond 1.1.4 → 2.0.0-rc10

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 (441) hide show
  1. package/CHANGELOG.md +143 -0
  2. package/LICENSE +201 -0
  3. package/README.md +642 -96
  4. package/api-promise.d.mts +2 -0
  5. package/api-promise.d.mts.map +1 -0
  6. package/api-promise.d.ts +2 -0
  7. package/api-promise.d.ts.map +1 -0
  8. package/api-promise.js +6 -0
  9. package/api-promise.js.map +1 -0
  10. package/api-promise.mjs +2 -0
  11. package/api-promise.mjs.map +1 -0
  12. package/client.d.mts +192 -0
  13. package/client.d.mts.map +1 -0
  14. package/client.d.ts +192 -0
  15. package/client.d.ts.map +1 -0
  16. package/client.js +463 -0
  17. package/client.js.map +1 -0
  18. package/client.mjs +459 -0
  19. package/client.mjs.map +1 -0
  20. package/core/api-promise.d.mts +46 -0
  21. package/core/api-promise.d.mts.map +1 -0
  22. package/core/api-promise.d.ts +46 -0
  23. package/core/api-promise.d.ts.map +1 -0
  24. package/core/api-promise.js +74 -0
  25. package/core/api-promise.js.map +1 -0
  26. package/core/api-promise.mjs +70 -0
  27. package/core/api-promise.mjs.map +1 -0
  28. package/core/error.d.mts +46 -0
  29. package/core/error.d.mts.map +1 -0
  30. package/core/error.d.ts +46 -0
  31. package/core/error.d.ts.map +1 -0
  32. package/core/error.js +113 -0
  33. package/core/error.js.map +1 -0
  34. package/core/error.mjs +97 -0
  35. package/core/error.mjs.map +1 -0
  36. package/core/resource.d.mts +6 -0
  37. package/core/resource.d.mts.map +1 -0
  38. package/core/resource.d.ts +6 -0
  39. package/core/resource.d.ts.map +1 -0
  40. package/core/resource.js +11 -0
  41. package/core/resource.js.map +1 -0
  42. package/core/resource.mjs +7 -0
  43. package/core/resource.mjs.map +1 -0
  44. package/core/uploads.d.mts +3 -0
  45. package/core/uploads.d.mts.map +1 -0
  46. package/core/uploads.d.ts +3 -0
  47. package/core/uploads.d.ts.map +1 -0
  48. package/core/uploads.js +6 -0
  49. package/core/uploads.js.map +1 -0
  50. package/core/uploads.mjs +2 -0
  51. package/core/uploads.mjs.map +1 -0
  52. package/error.d.mts +2 -0
  53. package/error.d.mts.map +1 -0
  54. package/error.d.ts +2 -0
  55. package/error.d.ts.map +1 -0
  56. package/error.js +6 -0
  57. package/error.js.map +1 -0
  58. package/error.mjs +2 -0
  59. package/error.mjs.map +1 -0
  60. package/index.d.mts +6 -0
  61. package/index.d.mts.map +1 -0
  62. package/index.d.ts +6 -0
  63. package/index.d.ts.map +1 -0
  64. package/index.js +30 -0
  65. package/index.js.map +1 -0
  66. package/index.mjs +7 -0
  67. package/index.mjs.map +1 -0
  68. package/internal/builtin-types.d.mts +73 -0
  69. package/internal/builtin-types.d.mts.map +1 -0
  70. package/internal/builtin-types.d.ts +73 -0
  71. package/internal/builtin-types.d.ts.map +1 -0
  72. package/internal/builtin-types.js +4 -0
  73. package/internal/builtin-types.js.map +1 -0
  74. package/internal/builtin-types.mjs +3 -0
  75. package/internal/builtin-types.mjs.map +1 -0
  76. package/internal/detect-platform.d.mts +15 -0
  77. package/internal/detect-platform.d.mts.map +1 -0
  78. package/internal/detect-platform.d.ts +15 -0
  79. package/internal/detect-platform.d.ts.map +1 -0
  80. package/internal/detect-platform.js +162 -0
  81. package/internal/detect-platform.js.map +1 -0
  82. package/internal/detect-platform.mjs +157 -0
  83. package/internal/detect-platform.mjs.map +1 -0
  84. package/internal/errors.d.mts +3 -0
  85. package/internal/errors.d.mts.map +1 -0
  86. package/internal/errors.d.ts +3 -0
  87. package/internal/errors.d.ts.map +1 -0
  88. package/internal/errors.js +41 -0
  89. package/internal/errors.js.map +1 -0
  90. package/internal/errors.mjs +36 -0
  91. package/internal/errors.mjs.map +1 -0
  92. package/internal/headers.d.mts +20 -0
  93. package/internal/headers.d.mts.map +1 -0
  94. package/internal/headers.d.ts +20 -0
  95. package/internal/headers.d.ts.map +1 -0
  96. package/internal/headers.js +79 -0
  97. package/internal/headers.js.map +1 -0
  98. package/internal/headers.mjs +74 -0
  99. package/internal/headers.mjs.map +1 -0
  100. package/internal/parse.d.mts +12 -0
  101. package/internal/parse.d.mts.map +1 -0
  102. package/internal/parse.d.ts +12 -0
  103. package/internal/parse.d.ts.map +1 -0
  104. package/internal/parse.js +35 -0
  105. package/internal/parse.js.map +1 -0
  106. package/internal/parse.mjs +32 -0
  107. package/internal/parse.mjs.map +1 -0
  108. package/internal/qs/formats.d.mts +7 -0
  109. package/internal/qs/formats.d.mts.map +1 -0
  110. package/internal/qs/formats.d.ts +7 -0
  111. package/internal/qs/formats.d.ts.map +1 -0
  112. package/internal/qs/formats.js +13 -0
  113. package/internal/qs/formats.js.map +1 -0
  114. package/internal/qs/formats.mjs +9 -0
  115. package/internal/qs/formats.mjs.map +1 -0
  116. package/internal/qs/index.d.mts +10 -0
  117. package/internal/qs/index.d.mts.map +1 -0
  118. package/internal/qs/index.d.ts +10 -0
  119. package/internal/qs/index.d.ts.map +1 -0
  120. package/internal/qs/index.js +14 -0
  121. package/internal/qs/index.js.map +1 -0
  122. package/internal/qs/index.mjs +10 -0
  123. package/internal/qs/index.mjs.map +1 -0
  124. package/internal/qs/stringify.d.mts +3 -0
  125. package/internal/qs/stringify.d.mts.map +1 -0
  126. package/internal/qs/stringify.d.ts +3 -0
  127. package/internal/qs/stringify.d.ts.map +1 -0
  128. package/internal/qs/stringify.js +277 -0
  129. package/internal/qs/stringify.js.map +1 -0
  130. package/internal/qs/stringify.mjs +274 -0
  131. package/internal/qs/stringify.mjs.map +1 -0
  132. package/internal/qs/types.d.mts +57 -0
  133. package/internal/qs/types.d.mts.map +1 -0
  134. package/internal/qs/types.d.ts +57 -0
  135. package/internal/qs/types.d.ts.map +1 -0
  136. package/internal/qs/types.js +3 -0
  137. package/internal/qs/types.js.map +1 -0
  138. package/internal/qs/types.mjs +2 -0
  139. package/internal/qs/types.mjs.map +1 -0
  140. package/internal/qs/utils.d.mts +15 -0
  141. package/internal/qs/utils.d.mts.map +1 -0
  142. package/internal/qs/utils.d.ts +15 -0
  143. package/internal/qs/utils.d.ts.map +1 -0
  144. package/internal/qs/utils.js +230 -0
  145. package/internal/qs/utils.js.map +1 -0
  146. package/internal/qs/utils.mjs +217 -0
  147. package/internal/qs/utils.mjs.map +1 -0
  148. package/internal/request-options.d.mts +75 -0
  149. package/internal/request-options.d.mts.map +1 -0
  150. package/internal/request-options.d.ts +75 -0
  151. package/internal/request-options.d.ts.map +1 -0
  152. package/internal/request-options.js +14 -0
  153. package/internal/request-options.js.map +1 -0
  154. package/internal/request-options.mjs +10 -0
  155. package/internal/request-options.mjs.map +1 -0
  156. package/internal/shim-types.d.mts +17 -0
  157. package/internal/shim-types.d.mts.map +1 -0
  158. package/internal/shim-types.d.ts +17 -0
  159. package/internal/shim-types.d.ts.map +1 -0
  160. package/internal/shim-types.js +4 -0
  161. package/internal/shim-types.js.map +1 -0
  162. package/internal/shim-types.mjs +3 -0
  163. package/internal/shim-types.mjs.map +1 -0
  164. package/internal/shims.d.mts +20 -0
  165. package/internal/shims.d.mts.map +1 -0
  166. package/internal/shims.d.ts +20 -0
  167. package/internal/shims.d.ts.map +1 -0
  168. package/internal/shims.js +92 -0
  169. package/internal/shims.js.map +1 -0
  170. package/internal/shims.mjs +85 -0
  171. package/internal/shims.mjs.map +1 -0
  172. package/internal/to-file.d.mts +45 -0
  173. package/internal/to-file.d.mts.map +1 -0
  174. package/internal/to-file.d.ts +45 -0
  175. package/internal/to-file.d.ts.map +1 -0
  176. package/internal/to-file.js +91 -0
  177. package/internal/to-file.js.map +1 -0
  178. package/internal/to-file.mjs +88 -0
  179. package/internal/to-file.mjs.map +1 -0
  180. package/internal/tslib.js +81 -0
  181. package/internal/tslib.mjs +17 -0
  182. package/internal/types.d.mts +69 -0
  183. package/internal/types.d.mts.map +1 -0
  184. package/internal/types.d.ts +69 -0
  185. package/internal/types.d.ts.map +1 -0
  186. package/internal/types.js +4 -0
  187. package/internal/types.js.map +1 -0
  188. package/internal/types.mjs +3 -0
  189. package/internal/types.mjs.map +1 -0
  190. package/internal/uploads.d.mts +42 -0
  191. package/internal/uploads.d.mts.map +1 -0
  192. package/internal/uploads.d.ts +42 -0
  193. package/internal/uploads.d.ts.map +1 -0
  194. package/internal/uploads.js +141 -0
  195. package/internal/uploads.js.map +1 -0
  196. package/internal/uploads.mjs +131 -0
  197. package/internal/uploads.mjs.map +1 -0
  198. package/internal/utils/base64.d.mts +3 -0
  199. package/internal/utils/base64.d.mts.map +1 -0
  200. package/internal/utils/base64.d.ts +3 -0
  201. package/internal/utils/base64.d.ts.map +1 -0
  202. package/internal/utils/base64.js +38 -0
  203. package/internal/utils/base64.js.map +1 -0
  204. package/internal/utils/base64.mjs +33 -0
  205. package/internal/utils/base64.mjs.map +1 -0
  206. package/internal/utils/bytes.d.mts +4 -0
  207. package/internal/utils/bytes.d.mts.map +1 -0
  208. package/internal/utils/bytes.d.ts +4 -0
  209. package/internal/utils/bytes.d.ts.map +1 -0
  210. package/internal/utils/bytes.js +31 -0
  211. package/internal/utils/bytes.js.map +1 -0
  212. package/internal/utils/bytes.mjs +26 -0
  213. package/internal/utils/bytes.mjs.map +1 -0
  214. package/internal/utils/env.d.mts +9 -0
  215. package/internal/utils/env.d.mts.map +1 -0
  216. package/internal/utils/env.d.ts +9 -0
  217. package/internal/utils/env.d.ts.map +1 -0
  218. package/internal/utils/env.js +24 -0
  219. package/internal/utils/env.js.map +1 -0
  220. package/internal/utils/env.mjs +20 -0
  221. package/internal/utils/env.mjs.map +1 -0
  222. package/internal/utils/log.d.mts +37 -0
  223. package/internal/utils/log.d.mts.map +1 -0
  224. package/internal/utils/log.d.ts +37 -0
  225. package/internal/utils/log.d.ts.map +1 -0
  226. package/internal/utils/log.js +85 -0
  227. package/internal/utils/log.js.map +1 -0
  228. package/internal/utils/log.mjs +79 -0
  229. package/internal/utils/log.mjs.map +1 -0
  230. package/internal/utils/path.d.mts +15 -0
  231. package/internal/utils/path.d.mts.map +1 -0
  232. package/internal/utils/path.d.ts +15 -0
  233. package/internal/utils/path.d.ts.map +1 -0
  234. package/internal/utils/path.js +79 -0
  235. package/internal/utils/path.js.map +1 -0
  236. package/internal/utils/path.mjs +74 -0
  237. package/internal/utils/path.mjs.map +1 -0
  238. package/internal/utils/sleep.d.mts +2 -0
  239. package/internal/utils/sleep.d.mts.map +1 -0
  240. package/internal/utils/sleep.d.ts +2 -0
  241. package/internal/utils/sleep.d.ts.map +1 -0
  242. package/internal/utils/sleep.js +7 -0
  243. package/internal/utils/sleep.js.map +1 -0
  244. package/internal/utils/sleep.mjs +3 -0
  245. package/internal/utils/sleep.mjs.map +1 -0
  246. package/internal/utils/uuid.d.mts +5 -0
  247. package/internal/utils/uuid.d.mts.map +1 -0
  248. package/internal/utils/uuid.d.ts +5 -0
  249. package/internal/utils/uuid.d.ts.map +1 -0
  250. package/internal/utils/uuid.js +19 -0
  251. package/internal/utils/uuid.js.map +1 -0
  252. package/internal/utils/uuid.mjs +15 -0
  253. package/internal/utils/uuid.mjs.map +1 -0
  254. package/internal/utils/values.d.mts +18 -0
  255. package/internal/utils/values.d.mts.map +1 -0
  256. package/internal/utils/values.d.ts +18 -0
  257. package/internal/utils/values.d.ts.map +1 -0
  258. package/internal/utils/values.js +112 -0
  259. package/internal/utils/values.js.map +1 -0
  260. package/internal/utils/values.mjs +94 -0
  261. package/internal/utils/values.mjs.map +1 -0
  262. package/internal/utils.d.mts +7 -0
  263. package/internal/utils.d.mts.map +1 -0
  264. package/internal/utils.d.ts +7 -0
  265. package/internal/utils.d.ts.map +1 -0
  266. package/internal/utils.js +11 -0
  267. package/internal/utils.js.map +1 -0
  268. package/internal/utils.mjs +8 -0
  269. package/internal/utils.mjs.map +1 -0
  270. package/package.json +129 -123
  271. package/resource.d.mts +2 -0
  272. package/resource.d.mts.map +1 -0
  273. package/resource.d.ts +2 -0
  274. package/resource.d.ts.map +1 -0
  275. package/resource.js +6 -0
  276. package/resource.js.map +1 -0
  277. package/resource.mjs +2 -0
  278. package/resource.mjs.map +1 -0
  279. package/resources/custom-router.d.mts +145 -0
  280. package/resources/custom-router.d.mts.map +1 -0
  281. package/resources/custom-router.d.ts +145 -0
  282. package/resources/custom-router.d.ts.map +1 -0
  283. package/resources/custom-router.js +83 -0
  284. package/resources/custom-router.js.map +1 -0
  285. package/resources/custom-router.mjs +79 -0
  286. package/resources/custom-router.mjs.map +1 -0
  287. package/resources/index.d.mts +7 -0
  288. package/resources/index.d.mts.map +1 -0
  289. package/resources/index.d.ts +7 -0
  290. package/resources/index.d.ts.map +1 -0
  291. package/resources/index.js +17 -0
  292. package/resources/index.js.map +1 -0
  293. package/resources/index.mjs +8 -0
  294. package/resources/index.mjs.map +1 -0
  295. package/resources/model-router.d.mts +196 -0
  296. package/resources/model-router.d.mts.map +1 -0
  297. package/resources/model-router.d.ts +196 -0
  298. package/resources/model-router.d.ts.map +1 -0
  299. package/resources/model-router.js +70 -0
  300. package/resources/model-router.js.map +1 -0
  301. package/resources/model-router.mjs +66 -0
  302. package/resources/model-router.mjs.map +1 -0
  303. package/resources/models.d.mts +110 -0
  304. package/resources/models.d.mts.map +1 -0
  305. package/resources/models.d.ts +110 -0
  306. package/resources/models.d.ts.map +1 -0
  307. package/resources/models.js +49 -0
  308. package/resources/models.js.map +1 -0
  309. package/resources/models.mjs +45 -0
  310. package/resources/models.mjs.map +1 -0
  311. package/resources/preferences.d.mts +97 -0
  312. package/resources/preferences.d.mts.map +1 -0
  313. package/resources/preferences.d.ts +97 -0
  314. package/resources/preferences.d.ts.map +1 -0
  315. package/resources/preferences.js +70 -0
  316. package/resources/preferences.js.map +1 -0
  317. package/resources/preferences.mjs +66 -0
  318. package/resources/preferences.mjs.map +1 -0
  319. package/resources/prompt-adaptation.d.mts +679 -0
  320. package/resources/prompt-adaptation.d.mts.map +1 -0
  321. package/resources/prompt-adaptation.d.ts +679 -0
  322. package/resources/prompt-adaptation.d.ts.map +1 -0
  323. package/resources/prompt-adaptation.js +266 -0
  324. package/resources/prompt-adaptation.js.map +1 -0
  325. package/resources/prompt-adaptation.mjs +262 -0
  326. package/resources/prompt-adaptation.mjs.map +1 -0
  327. package/resources/report/index.d.mts +3 -0
  328. package/resources/report/index.d.mts.map +1 -0
  329. package/resources/report/index.d.ts +3 -0
  330. package/resources/report/index.d.ts.map +1 -0
  331. package/resources/report/index.js +9 -0
  332. package/resources/report/index.js.map +1 -0
  333. package/resources/report/index.mjs +4 -0
  334. package/resources/report/index.mjs.map +1 -0
  335. package/resources/report/metrics.d.mts +87 -0
  336. package/resources/report/metrics.d.mts.map +1 -0
  337. package/resources/report/metrics.d.ts +87 -0
  338. package/resources/report/metrics.d.ts.map +1 -0
  339. package/resources/report/metrics.js +57 -0
  340. package/resources/report/metrics.js.map +1 -0
  341. package/resources/report/metrics.mjs +53 -0
  342. package/resources/report/metrics.mjs.map +1 -0
  343. package/resources/report/report.d.mts +10 -0
  344. package/resources/report/report.d.mts.map +1 -0
  345. package/resources/report/report.d.ts +10 -0
  346. package/resources/report/report.d.ts.map +1 -0
  347. package/resources/report/report.js +17 -0
  348. package/resources/report/report.js.map +1 -0
  349. package/resources/report/report.mjs +12 -0
  350. package/resources/report/report.mjs.map +1 -0
  351. package/resources/report.d.mts +2 -0
  352. package/resources/report.d.mts.map +1 -0
  353. package/resources/report.d.ts +2 -0
  354. package/resources/report.d.ts.map +1 -0
  355. package/resources/report.js +6 -0
  356. package/resources/report.js.map +1 -0
  357. package/resources/report.mjs +3 -0
  358. package/resources/report.mjs.map +1 -0
  359. package/resources.d.mts +2 -0
  360. package/resources.d.mts.map +1 -0
  361. package/resources.d.ts +2 -0
  362. package/resources.d.ts.map +1 -0
  363. package/resources.js +5 -0
  364. package/resources.js.map +1 -0
  365. package/resources.mjs +2 -0
  366. package/resources.mjs.map +1 -0
  367. package/src/api-promise.ts +2 -0
  368. package/src/client.ts +791 -0
  369. package/src/core/README.md +3 -0
  370. package/src/core/api-promise.ts +92 -0
  371. package/src/core/error.ts +130 -0
  372. package/src/core/resource.ts +11 -0
  373. package/src/core/uploads.ts +2 -0
  374. package/src/error.ts +2 -0
  375. package/src/index.ts +22 -0
  376. package/src/internal/README.md +3 -0
  377. package/src/internal/builtin-types.ts +93 -0
  378. package/src/internal/detect-platform.ts +196 -0
  379. package/src/internal/errors.ts +33 -0
  380. package/src/internal/headers.ts +97 -0
  381. package/src/internal/parse.ts +50 -0
  382. package/src/internal/qs/LICENSE.md +13 -0
  383. package/src/internal/qs/README.md +3 -0
  384. package/src/internal/qs/formats.ts +10 -0
  385. package/src/internal/qs/index.ts +13 -0
  386. package/src/internal/qs/stringify.ts +385 -0
  387. package/src/internal/qs/types.ts +71 -0
  388. package/src/internal/qs/utils.ts +265 -0
  389. package/src/internal/request-options.ts +91 -0
  390. package/src/internal/shim-types.ts +26 -0
  391. package/src/internal/shims.ts +107 -0
  392. package/src/internal/to-file.ts +154 -0
  393. package/src/internal/types.ts +95 -0
  394. package/src/internal/uploads.ts +187 -0
  395. package/src/internal/utils/base64.ts +40 -0
  396. package/src/internal/utils/bytes.ts +32 -0
  397. package/src/internal/utils/env.ts +20 -0
  398. package/src/internal/utils/log.ts +126 -0
  399. package/src/internal/utils/path.ts +88 -0
  400. package/src/internal/utils/sleep.ts +3 -0
  401. package/src/internal/utils/uuid.ts +17 -0
  402. package/src/internal/utils/values.ts +105 -0
  403. package/src/internal/utils.ts +8 -0
  404. package/src/lib/.keep +4 -0
  405. package/src/resource.ts +2 -0
  406. package/src/resources/custom-router.ts +168 -0
  407. package/src/resources/index.ts +33 -0
  408. package/src/resources/model-router.ts +224 -0
  409. package/src/resources/models.ts +133 -0
  410. package/src/resources/preferences.ts +121 -0
  411. package/src/resources/prompt-adaptation.ts +770 -0
  412. package/src/resources/report/index.ts +4 -0
  413. package/src/resources/report/metrics.ts +99 -0
  414. package/src/resources/report/report.ts +19 -0
  415. package/src/resources/report.ts +3 -0
  416. package/src/resources.ts +1 -0
  417. package/src/tsconfig.json +11 -0
  418. package/src/uploads.ts +2 -0
  419. package/src/version.ts +1 -0
  420. package/uploads.d.mts +2 -0
  421. package/uploads.d.mts.map +1 -0
  422. package/uploads.d.ts +2 -0
  423. package/uploads.d.ts.map +1 -0
  424. package/uploads.js +6 -0
  425. package/uploads.js.map +1 -0
  426. package/uploads.mjs +2 -0
  427. package/uploads.mjs.map +1 -0
  428. package/version.d.mts +2 -0
  429. package/version.d.mts.map +1 -0
  430. package/version.d.ts +2 -0
  431. package/version.d.ts.map +1 -0
  432. package/version.js +5 -0
  433. package/version.js.map +1 -0
  434. package/version.mjs +2 -0
  435. package/version.mjs.map +1 -0
  436. package/LICENCE +0 -21
  437. package/dist/index.cjs +0 -601
  438. package/dist/index.d.cts +0 -228
  439. package/dist/index.d.mts +0 -228
  440. package/dist/index.d.ts +0 -228
  441. package/dist/index.mjs +0 -580
package/README.md CHANGED
@@ -1,6 +1,29 @@
1
- # NotDiamond Node API Library
1
+ # Not Diamond TypeScript API Library
2
2
 
3
- This library provides convenient access to the NotDiamond model routing API from TypeScript or JavaScript. NotDiamond helps you select the best AI model for your specific use case, optimizing for factors like cost, latency, or performance.
3
+ [![NPM version](<https://img.shields.io/npm/v/notdiamond.svg?label=npm%20(stable)>)](https://npmjs.org/package/notdiamond) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/notdiamond)
4
+
5
+ This library provides convenient access to the Not Diamond REST API from server-side TypeScript or JavaScript.
6
+
7
+ The library includes type definitions for all request params and response fields.
8
+
9
+ It is generated with [Stainless](https://www.stainless.com/).
10
+
11
+ ## What is Prompt Adaptation?
12
+
13
+ Not Diamond specializes in **Prompt Adaptation** - automatically optimizing your prompts to work optimally across different LLMs. Each language model has unique characteristics, instruction-following patterns, and preferred prompt formats. A prompt that works perfectly for GPT-4 might perform poorly on Claude or Gemini.
14
+
15
+ **The Problem**: Manually rewriting prompts for each model is time-consuming and requires deep expertise in each model's quirks.
16
+
17
+ **The Solution**: Not Diamond automatically adapts your prompts through:
18
+
19
+ - Systematic optimization using your evaluation dataset
20
+ - Automated testing across target models
21
+ - Performance metrics to validate improvements
22
+ - Both system prompt and user message template optimization
23
+
24
+ ## Documentation
25
+
26
+ The REST API documentation can be found on [docs.notdiamond.ai](https://docs.notdiamond.ai). The full API of this library can be found in [api.md](api.md).
4
27
 
5
28
  ## Installation
6
29
 
@@ -8,135 +31,658 @@ This library provides convenient access to the NotDiamond model routing API from
8
31
  npm install notdiamond
9
32
  ```
10
33
 
11
- For Deno users:
34
+ ## Usage
35
+
36
+ ### Prompt Adaptation
37
+
38
+ Automatically optimize your prompts to work better across different language models. Each model has unique characteristics and preferences - what works well for GPT-4 might not work as well for Claude or Gemini. Prompt Adaptation helps you get optimal performance from each model.
39
+
40
+ #### Quick Start
41
+
42
+ <!-- prettier-ignore -->
43
+ ```ts
44
+ import NotDiamond from 'notdiamond';
45
+
46
+ const client = new NotDiamond({
47
+ apiKey: process.env['NOT_DIAMOND_API_KEY'], // This is the default and can be omitted
48
+ });
49
+
50
+ // Step 1: Start a prompt adaptation job
51
+ const adaptation = await client.prompt.adapt.create({
52
+ fields: ['question'],
53
+ system_prompt: 'You are a helpful assistant that answers questions accurately.',
54
+ target_models: [
55
+ {
56
+ model: 'claude-sonnet-4-5-20250929',
57
+ provider: 'anthropic',
58
+ },
59
+ {
60
+ model: 'gemini-2.5-flash',
61
+ provider: 'google',
62
+ },
63
+ ],
64
+ template: 'Question: {question}\nAnswer:',
65
+ train_goldens: [
66
+ { fields: { question: 'What is 2+2?' }, answer: '4' },
67
+ { fields: { question: 'What is the capital of France?' }, answer: 'Paris' },
68
+ { fields: { question: 'Who wrote Romeo and Juliet?' }, answer: 'William Shakespeare' },
69
+ // Add at least 25 training examples for best results
70
+ // More examples = better adaptation quality
71
+ ],
72
+ test_goldens: [
73
+ { fields: { question: 'What is 3*3?' }, answer: '9' },
74
+ { fields: { question: 'What is the largest ocean?' }, answer: 'Pacific Ocean' },
75
+ // Add test examples to validate performance
76
+ ],
77
+ evaluation_metric: 'LLMaaJ:Sem_Sim_1', // Or use custom evaluation
78
+ });
79
+
80
+ console.log(`Adaptation started: ${adaptation.adaptation_run_id}`);
81
+
82
+ // Step 2: Poll for completion (typically takes 10-30 minutes)
83
+ let status;
84
+ while (true) {
85
+ status = await client.prompt.getAdaptStatus(adaptation.adaptation_run_id);
86
+ console.log(`Status: ${status.status}`);
87
+
88
+ if (status.status === 'queued') {
89
+ console.log(`Queue position: ${status.queue_position}`);
90
+ }
91
+
92
+ if (status.status === 'completed' || status.status === 'failed') {
93
+ break;
94
+ }
95
+
96
+ await new Promise(resolve => setTimeout(resolve, 30000)); // Poll every 30 seconds
97
+ }
98
+
99
+ // Step 3: Get the optimized prompts
100
+ if (status.status === 'completed') {
101
+ const results = await client.prompt.getAdaptResults(adaptation.adaptation_run_id);
102
+
103
+ console.log(`\nOrigin model baseline: ${results.origin_model.score.toFixed(2)}`);
104
+
105
+ for (const target of results.target_models) {
106
+ console.log('\n' + '='.repeat(50));
107
+ console.log(`Model: ${target.model.model} (${target.model.provider})`);
108
+ console.log(`Optimized System Prompt:\n${target.system_prompt}`);
109
+ console.log(`Optimized Template:\n${target.user_message_template}`);
110
+ console.log(`Pre-optimization score: ${target.pre_optimization_score.toFixed(2)}`);
111
+ console.log(`Post-optimization score: ${target.post_optimization_score.toFixed(2)}`);
112
+ console.log(`Improvement: ${((target.post_optimization_score / target.pre_optimization_score - 1) * 100).toFixed(1)}%`);
113
+ console.log(`Cost: $${target.cost.toFixed(4)}`);
114
+ }
115
+ }
116
+ ```
117
+
118
+ #### Key Features
119
+
120
+ - **Automatic Optimization**: Adapts both system prompts and user message templates
121
+ - **Evaluation Metrics**: Choose from standard metrics (semantic similarity, JSON matching, SQL) or provide custom evaluation
122
+ - **Dataset Requirements**: Minimum 25 training examples (more examples = better results)
123
+ - **Processing Time**: Typically 10-30 minutes depending on dataset size and number of target models
124
+ - **Subscription Tiers**: Support for 1-10 target models depending on your plan
125
+
126
+ #### Evaluation Metrics
127
+
128
+ Choose from standard metrics:
129
+
130
+ - `LLMaaJ:Sem_Sim_1`, `LLMaaJ:Sem_Sim_3`, `LLMaaJ:Sem_Sim_10` - Semantic similarity
131
+ - `LLMaaJ:SQL` - SQL query validation
132
+ - `JSON_Match` - JSON structure matching
133
+
134
+ Or provide custom evaluation configuration with your own LLM judge.
135
+
136
+ #### Best Practices
137
+
138
+ 1. **Use Representative Examples**: Include diverse examples from your production workload
139
+ 2. **Sufficient Dataset Size**: Use at least 25 training examples (50+ recommended)
140
+ 3. **Train/Test Split**: Separate train_goldens and test_goldens for proper validation
141
+ 4. **A/B Test Results**: Validate optimized prompts in production before full deployment
142
+
143
+ For more details, see the [Prompt Adaptation documentation](https://docs.notdiamond.ai/docs/adapting-prompts-to-new-models).
144
+
145
+ ### Model Routing
146
+
147
+ Not Diamond also provides intelligent model routing to select the best model for your query:
148
+
149
+ <!-- prettier-ignore -->
150
+ ```ts
151
+ const response = await client.modelRouter.selectModel({
152
+ llm_providers: [
153
+ { model: 'gpt-4o', provider: 'openai' },
154
+ { model: 'claude-sonnet-4-5-20250929', provider: 'anthropic' },
155
+ { model: 'gemini-2.5-flash', provider: 'google' },
156
+ ],
157
+ messages: [
158
+ { role: 'system', content: 'You are a helpful assistant.' },
159
+ { role: 'user', content: 'Explain quantum computing in simple terms' },
160
+ ],
161
+ });
162
+
163
+ console.log(response.providers);
164
+ ```
165
+
166
+ ### Request & Response types
167
+
168
+ This library includes TypeScript definitions for all request params and response fields. You may import and use them like so:
12
169
 
170
+ <!-- prettier-ignore -->
13
171
  ```ts
14
- import { NotDiamond } from 'https://deno.land/x/notdiamond@v1.0.0/mod.ts';
172
+ import NotDiamond from 'notdiamond';
173
+
174
+ const client = new NotDiamond({
175
+ apiKey: process.env['NOT_DIAMOND_API_KEY'], // This is the default and can be omitted
176
+ });
177
+
178
+ const params: NotDiamond.PromptAdaptCreateParams = {
179
+ fields: ['question', 'context'],
180
+ system_prompt: 'You are a helpful assistant.',
181
+ target_models: [
182
+ {
183
+ model: 'claude-sonnet-4-5-20250929',
184
+ provider: 'anthropic',
185
+ },
186
+ ],
187
+ template: 'Context: {context}\nQuestion: {question}\nAnswer:',
188
+ train_goldens: [
189
+ {
190
+ fields: {
191
+ question: 'What is 2+2?',
192
+ context: 'Basic arithmetic',
193
+ },
194
+ answer: '4',
195
+ },
196
+ // Add at least 25 examples for best results
197
+ ],
198
+ test_goldens: [
199
+ {
200
+ fields: {
201
+ question: 'What is 3*3?',
202
+ context: 'Basic arithmetic',
203
+ },
204
+ answer: '9',
205
+ },
206
+ ],
207
+ };
208
+ const response: NotDiamond.PromptAdaptCreateResponse = await client.prompt.adapt.create(params);
209
+ console.log(response.adaptation_run_id);
15
210
  ```
16
211
 
17
- ## Quick Start
212
+ Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
213
+
214
+ ## File uploads
18
215
 
19
- To use the API, you need to sign up for a NotDiamond account and obtain an API key. [Sign up here](https://app.notdiamond.ai).
216
+ Request parameters that correspond to file uploads can be passed in many different forms:
20
217
 
21
- ### Basic Usage
218
+ - `File` (or an object with the same structure)
219
+ - a `fetch` `Response` (or an object with the same structure)
220
+ - an `fs.ReadStream`
221
+ - the return value of our `toFile` helper
222
+
223
+ ```ts
224
+ import fs from 'fs';
225
+ import NotDiamond, { toFile } from 'notdiamond';
226
+
227
+ const client = new NotDiamond();
228
+
229
+ // If you have access to Node `fs` we recommend using `fs.createReadStream()`:
230
+ await client.customRouter.trainCustomRouter({
231
+ dataset_file: fs.createReadStream('/path/to/file'),
232
+ language: 'english',
233
+ llm_providers:
234
+ '[{"provider": "openai", "model": "gpt-4o"}, {"provider": "anthropic", "model": "claude-sonnet-4-5-20250929"}]',
235
+ maximize: true,
236
+ prompt_column: 'prompt',
237
+ });
22
238
 
23
- Here's a simple example of how to use NotDiamond to select the best model between GPT-4o, Claude 3.5 Sonnet, and Gemini 1.5 Pro, while optimizing for latency and outputting the raw text:
239
+ // Or if you have the web `File` API you can pass a `File` instance:
240
+ await client.customRouter.trainCustomRouter({
241
+ dataset_file: new File(['my bytes'], 'file'),
242
+ language: 'english',
243
+ llm_providers:
244
+ '[{"provider": "openai", "model": "gpt-4o"}, {"provider": "anthropic", "model": "claude-sonnet-4-5-20250929"}]',
245
+ maximize: true,
246
+ prompt_column: 'prompt',
247
+ });
24
248
 
25
- ```typescript
26
- import { NotDiamond } from 'notdiamond';
249
+ // You can also pass a `fetch` `Response`:
250
+ await client.customRouter.trainCustomRouter({
251
+ dataset_file: await fetch('https://somesite/file'),
252
+ language: 'english',
253
+ llm_providers:
254
+ '[{"provider": "openai", "model": "gpt-4o"}, {"provider": "anthropic", "model": "claude-sonnet-4-5-20250929"}]',
255
+ maximize: true,
256
+ prompt_column: 'prompt',
257
+ });
27
258
 
28
- const notDiamond = new NotDiamond({
29
- // Optional - automatically loads from environment variable
30
- apiKey: process.env.NOTDIAMOND_API_KEY,
259
+ // Finally, if none of the above are convenient, you can use our `toFile` helper:
260
+ await client.customRouter.trainCustomRouter({
261
+ dataset_file: await toFile(Buffer.from('my bytes'), 'file'),
262
+ language: 'english',
263
+ llm_providers:
264
+ '[{"provider": "openai", "model": "gpt-4o"}, {"provider": "anthropic", "model": "claude-sonnet-4-5-20250929"}]',
265
+ maximize: true,
266
+ prompt_column: 'prompt',
267
+ });
268
+ await client.customRouter.trainCustomRouter({
269
+ dataset_file: await toFile(new Uint8Array([0, 1, 2]), 'file'),
270
+ language: 'english',
271
+ llm_providers:
272
+ '[{"provider": "openai", "model": "gpt-4o"}, {"provider": "anthropic", "model": "claude-sonnet-4-5-20250929"}]',
273
+ maximize: true,
274
+ prompt_column: 'prompt',
31
275
  });
276
+ ```
277
+
278
+ ## Handling errors
279
+
280
+ When the library is unable to connect to the API,
281
+ or if the API returns a non-success status code (i.e., 4xx or 5xx response),
282
+ a subclass of `APIError` will be thrown:
32
283
 
33
- async function basicExample() {
34
- // 1. Select the best model
35
- const result = await notDiamond.create({
36
- // Define the user's message
37
- messages: [{ content: 'What is 12x12?', role: 'user' }],
38
- // Specify the LLM providers and models to choose from
39
- llmProviders: [
40
- { provider: 'openai', model: 'gpt-4o-2024-05-13' },
41
- { provider: 'anthropic', model: 'claude-3-5-sonnet-20240620' },
42
- { provider: 'google', model: 'gemini-1.5-pro-latest' },
284
+ <!-- prettier-ignore -->
285
+ ```ts
286
+ import NotDiamond from 'notdiamond';
287
+
288
+ const client = new NotDiamond();
289
+
290
+ try {
291
+ await client.prompt.adapt.create({
292
+ fields: ['question'],
293
+ system_prompt: 'You are a helpful assistant.',
294
+ target_models: [
295
+ {
296
+ model: 'claude-sonnet-4-5-20250929',
297
+ provider: 'anthropic',
298
+ },
299
+ {
300
+ model: 'gemini-2.5-flash',
301
+ provider: 'google',
302
+ },
303
+ ],
304
+ template: 'Question: {question}\nAnswer:',
305
+ train_goldens: [
306
+ { fields: { question: 'What is 2+2?' }, answer: '4' },
307
+ // Add at least 25 examples...
308
+ ],
309
+ test_goldens: [
310
+ { fields: { question: 'What is 3*3?' }, answer: '9' },
43
311
  ],
44
- // Set the optimization criteria to latency
45
- tradeoff: 'latency',
46
312
  });
47
-
48
- // 2. Handle potential errors
49
- if ('detail' in result) {
50
- console.error('Error:', result.detail);
51
- return;
313
+ } catch (err) {
314
+ if (err instanceof NotDiamond.APIConnectionError) {
315
+ console.log('The server could not be reached');
316
+ console.log(err.cause); // an underlying Error, likely from fetch()
317
+ } else if (err instanceof NotDiamond.RateLimitError) {
318
+ console.log('A 429 status code was received; we should back off a bit.');
319
+ } else if (err instanceof NotDiamond.APIError) {
320
+ console.log(err.status); // 400
321
+ console.log(err.name); // BadRequestError
322
+ console.log(err.headers); // {server: 'nginx', ...}
323
+ } else {
324
+ throw err;
52
325
  }
53
-
54
- // 3. Log the results
55
- // Display the text response
56
- console.log('LLM output:', result.content);
57
- // Display the selected provider(s)
58
- console.log('Selected providers:', result.providers);
59
- // Show the unique session ID for this request
60
- console.log('Session ID:', result.session_id);
61
326
  }
327
+ ```
328
+
329
+ Error codes are as follows:
330
+
331
+ | Status Code | Error Type |
332
+ | ----------- | -------------------------- |
333
+ | 400 | `BadRequestError` |
334
+ | 401 | `AuthenticationError` |
335
+ | 403 | `PermissionDeniedError` |
336
+ | 404 | `NotFoundError` |
337
+ | 422 | `UnprocessableEntityError` |
338
+ | 429 | `RateLimitError` |
339
+ | >=500 | `InternalServerError` |
340
+ | N/A | `APIConnectionError` |
341
+
342
+ ### Retries
343
+
344
+ Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
345
+ Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,
346
+ 429 Rate Limit, and >=500 Internal errors will all be retried by default.
347
+
348
+ You can use the `maxRetries` option to configure or disable this:
349
+
350
+ <!-- prettier-ignore -->
351
+ ```js
352
+ // Configure the default for all requests:
353
+ const client = new NotDiamond({
354
+ maxRetries: 0, // default is 2
355
+ });
356
+
357
+ // Or, configure per-request:
358
+ await client.prompt.adapt.create({
359
+ fields: ['question'],
360
+ system_prompt: 'You are a helpful assistant.',
361
+ target_models: [
362
+ {
363
+ model: 'claude-sonnet-4-5-20250929',
364
+ provider: 'anthropic',
365
+ },
366
+ {
367
+ model: 'gemini-2.5-flash',
368
+ provider: 'google',
369
+ },
370
+ ],
371
+ template: 'Question: {question}\nAnswer:',
372
+ train_goldens: [
373
+ { fields: { question: 'What is 2+2?' }, answer: '4' },
374
+ // Add at least 25 examples...
375
+ ],
376
+ test_goldens: [
377
+ { fields: { question: 'What is 3*3?' }, answer: '9' },
378
+ ],
379
+ }, {
380
+ maxRetries: 5,
381
+ });
382
+ ```
383
+
384
+ ### Timeouts
385
+
386
+ Requests time out after 1 minute by default. You can configure this with a `timeout` option:
387
+
388
+ <!-- prettier-ignore -->
389
+ ```ts
390
+ // Configure the default for all requests:
391
+ const client = new NotDiamond({
392
+ timeout: 20 * 1000, // 20 seconds (default is 1 minute)
393
+ });
62
394
 
63
- basicExample();
395
+ // Override per-request (note: prompt adaptation may take 10-30 minutes, so increase timeout accordingly):
396
+ await client.prompt.getAdaptStatus('your-adaptation-run-id', {
397
+ timeout: 120 * 1000, // 2 minutes
398
+ });
64
399
  ```
65
400
 
66
- ### Advanced Usage with Tools
401
+ On timeout, an `APIConnectionTimeoutError` is thrown.
402
+
403
+ Note that requests which time out will be [retried twice by default](#retries).
67
404
 
68
- You can also use NotDiamond with custom tools:
405
+ ## Advanced Usage
69
406
 
70
- ```typescript
71
- import { NotDiamond, Tool } from 'notdiamond';
407
+ ### Accessing raw Response data (e.g., headers)
72
408
 
73
- const notDiamond = new NotDiamond();
409
+ The "raw" `Response` returned by `fetch()` can be accessed through the `.asResponse()` method on the `APIPromise` type that all methods return.
410
+ This method returns as soon as the headers for a successful response are received and does not consume the response body, so you are free to write custom parsing or streaming logic.
74
411
 
75
- // Define custom tools for the AI to use
76
- const tools: Tool[] = [
77
- {
78
- type: 'function',
79
- function: {
80
- name: 'multiply',
81
- description: 'Multiplies two numbers.',
82
- parameters: {
83
- type: 'object',
84
- properties: {
85
- a: { type: 'integer' },
86
- b: { type: 'integer' },
87
- },
88
- required: ['a', 'b'],
412
+ You can also use the `.withResponse()` method to get the raw `Response` along with the parsed data.
413
+ Unlike `.asResponse()` this method consumes the body, returning once it is parsed.
414
+
415
+ <!-- prettier-ignore -->
416
+ ```ts
417
+ const client = new NotDiamond();
418
+
419
+ const response = await client.prompt.adapt
420
+ .create({
421
+ fields: ['question'],
422
+ system_prompt: 'You are a helpful assistant.',
423
+ target_models: [
424
+ {
425
+ model: 'claude-sonnet-4-5-20250929',
426
+ provider: 'anthropic',
427
+ },
428
+ {
429
+ model: 'gemini-2.5-flash',
430
+ provider: 'google',
89
431
  },
90
- },
91
- },
92
- ];
93
-
94
- async function toolCallingExample() {
95
- const result = await notDiamond.modelSelect({
96
- messages: [{ content: 'What is 12x12?', role: 'user' }],
97
- llmProviders: [
98
- { provider: 'openai', model: 'gpt-4-1106-preview' },
99
- { provider: 'anthropic', model: 'claude-3-sonnet-20240229' },
100
432
  ],
101
- // Include custom tools in the request
102
- tools: tools,
103
- // Optimize for cost instead of latency
104
- tradeoff: 'cost',
105
- // Allow selection of up to 2 models
106
- maxModelDepth: 2,
107
- });
433
+ template: 'Question: {question}\nAnswer:',
434
+ train_goldens: [
435
+ { fields: { question: 'What is 2+2?' }, answer: '4' },
436
+ // Add at least 25 examples...
437
+ ],
438
+ test_goldens: [
439
+ { fields: { question: 'What is 3*3?' }, answer: '9' },
440
+ ],
441
+ })
442
+ .asResponse();
443
+ console.log(response.headers.get('X-My-Header'));
444
+ console.log(response.statusText); // access the underlying Response object
445
+
446
+ const { data: adaptResponse, response: raw } = await client.prompt.adapt
447
+ .create({
448
+ fields: ['question'],
449
+ system_prompt: 'You are a helpful assistant.',
450
+ target_models: [
451
+ {
452
+ model: 'claude-sonnet-4-5-20250929',
453
+ provider: 'anthropic',
454
+ },
455
+ {
456
+ model: 'gemini-2.5-flash',
457
+ provider: 'google',
458
+ },
459
+ ],
460
+ template: 'Question: {question}\nAnswer:',
461
+ train_goldens: [
462
+ { fields: { question: 'What is 2+2?' }, answer: '4' },
463
+ // Add at least 25 examples...
464
+ ],
465
+ test_goldens: [
466
+ { fields: { question: 'What is 3*3?' }, answer: '9' },
467
+ ],
468
+ })
469
+ .withResponse();
470
+ console.log(raw.headers.get('X-My-Header'));
471
+ console.log(adaptResponse.adaptation_run_id);
472
+ ```
108
473
 
109
- if ('detail' in result) {
110
- console.error('Error:', result.detail);
111
- return;
112
- }
474
+ ### Logging
113
475
 
114
- console.log('Selected providers:', result.providers);
115
- console.log('Session ID:', result.session_id);
116
- }
476
+ > [!IMPORTANT]
477
+ > All log messages are intended for debugging only. The format and content of log messages
478
+ > may change between releases.
479
+
480
+ #### Log levels
481
+
482
+ The log level can be configured in two ways:
483
+
484
+ 1. Via the `NOT_DIAMOND_LOG` environment variable
485
+ 2. Using the `logLevel` client option (overrides the environment variable if set)
486
+
487
+ ```ts
488
+ import NotDiamond from 'notdiamond';
489
+
490
+ const client = new NotDiamond({
491
+ logLevel: 'debug', // Show all log messages
492
+ });
493
+ ```
494
+
495
+ Available log levels, from most to least verbose:
496
+
497
+ - `'debug'` - Show debug messages, info, warnings, and errors
498
+ - `'info'` - Show info messages, warnings, and errors
499
+ - `'warn'` - Show warnings and errors (default)
500
+ - `'error'` - Show only errors
501
+ - `'off'` - Disable all logging
502
+
503
+ At the `'debug'` level, all HTTP requests and responses are logged, including headers and bodies.
504
+ Some authentication-related headers are redacted, but sensitive data in request and response bodies
505
+ may still be visible.
506
+
507
+ #### Custom logger
508
+
509
+ By default, this library logs to `globalThis.console`. You can also provide a custom logger.
510
+ Most logging libraries are supported, including [pino](https://www.npmjs.com/package/pino), [winston](https://www.npmjs.com/package/winston), [bunyan](https://www.npmjs.com/package/bunyan), [consola](https://www.npmjs.com/package/consola), [signale](https://www.npmjs.com/package/signale), and [@std/log](https://jsr.io/@std/log). If your logger doesn't work, please open an issue.
511
+
512
+ When providing a custom logger, the `logLevel` option still controls which messages are emitted, messages
513
+ below the configured level will not be sent to your logger.
514
+
515
+ ```ts
516
+ import NotDiamond from 'notdiamond';
517
+ import pino from 'pino';
518
+
519
+ const logger = pino();
520
+
521
+ const client = new NotDiamond({
522
+ logger: logger.child({ name: 'NotDiamond' }),
523
+ logLevel: 'debug', // Send all messages to pino, allowing it to filter
524
+ });
525
+ ```
526
+
527
+ ### Making custom/undocumented requests
528
+
529
+ This library is typed for convenient access to the documented API. If you need to access undocumented
530
+ endpoints, params, or response properties, the library can still be used.
531
+
532
+ #### Undocumented endpoints
533
+
534
+ To make requests to undocumented endpoints, you can use `client.get`, `client.post`, and other HTTP verbs.
535
+ Options on the client, such as retries, will be respected when making these requests.
536
+
537
+ ```ts
538
+ await client.post('/some/path', {
539
+ body: { some_prop: 'foo' },
540
+ query: { some_query_arg: 'bar' },
541
+ });
542
+ ```
543
+
544
+ #### Undocumented request params
545
+
546
+ To make requests using undocumented parameters, you may use `// @ts-expect-error` on the undocumented
547
+ parameter. This library doesn't validate at runtime that the request matches the type, so any extra values you
548
+ send will be sent as-is.
549
+
550
+ ```ts
551
+ client.prompt.adapt.create({
552
+ fields: ['question'],
553
+ system_prompt: 'You are a helpful assistant.',
554
+ target_models: [{ model: 'claude-sonnet-4-5-20250929', provider: 'anthropic' }],
555
+ template: 'Question: {question}\nAnswer:',
556
+ train_goldens: [{ fields: { question: 'What is 2+2?' }, answer: '4' }],
557
+ // @ts-expect-error experimental_feature is not yet public
558
+ experimental_feature: true,
559
+ });
560
+ ```
561
+
562
+ For requests with the `GET` verb, any extra params will be in the query, all other requests will send the
563
+ extra param in the body.
117
564
 
118
- toolCallingExample();
565
+ If you want to explicitly send an extra argument, you can do so with the `query`, `body`, and `headers` request
566
+ options.
567
+
568
+ #### Undocumented response properties
569
+
570
+ To access undocumented response properties, you may access the response object with `// @ts-expect-error` on
571
+ the response object, or cast the response object to the requisite type. Like the request params, we do not
572
+ validate or strip extra properties from the response from the API.
573
+
574
+ ### Customizing the fetch client
575
+
576
+ By default, this library expects a global `fetch` function is defined.
577
+
578
+ If you want to use a different `fetch` function, you can either polyfill the global:
579
+
580
+ ```ts
581
+ import fetch from 'my-fetch';
582
+
583
+ globalThis.fetch = fetch;
584
+ ```
585
+
586
+ Or pass it to the client:
587
+
588
+ ```ts
589
+ import NotDiamond from 'notdiamond';
590
+ import fetch from 'my-fetch';
591
+
592
+ const client = new NotDiamond({ fetch });
593
+ ```
594
+
595
+ ### Fetch options
596
+
597
+ If you want to set custom `fetch` options without overriding the `fetch` function, you can provide a `fetchOptions` object when instantiating the client or making a request. (Request-specific options override client options.)
598
+
599
+ ```ts
600
+ import NotDiamond from 'notdiamond';
601
+
602
+ const client = new NotDiamond({
603
+ fetchOptions: {
604
+ // `RequestInit` options
605
+ },
606
+ });
607
+ ```
608
+
609
+ #### Configuring proxies
610
+
611
+ To modify proxy behavior, you can provide custom `fetchOptions` that add runtime-specific proxy
612
+ options to requests:
613
+
614
+ <img src="https://raw.githubusercontent.com/stainless-api/sdk-assets/refs/heads/main/node.svg" align="top" width="18" height="21"> **Node** <sup>[[docs](https://github.com/nodejs/undici/blob/main/docs/docs/api/ProxyAgent.md#example---proxyagent-with-fetch)]</sup>
615
+
616
+ ```ts
617
+ import NotDiamond from 'notdiamond';
618
+ import * as undici from 'undici';
619
+
620
+ const proxyAgent = new undici.ProxyAgent('http://localhost:8888');
621
+ const client = new NotDiamond({
622
+ fetchOptions: {
623
+ dispatcher: proxyAgent,
624
+ },
625
+ });
626
+ ```
627
+
628
+ <img src="https://raw.githubusercontent.com/stainless-api/sdk-assets/refs/heads/main/bun.svg" align="top" width="18" height="21"> **Bun** <sup>[[docs](https://bun.sh/guides/http/proxy)]</sup>
629
+
630
+ ```ts
631
+ import NotDiamond from 'notdiamond';
632
+
633
+ const client = new NotDiamond({
634
+ fetchOptions: {
635
+ proxy: 'http://localhost:8888',
636
+ },
637
+ });
638
+ ```
639
+
640
+ <img src="https://raw.githubusercontent.com/stainless-api/sdk-assets/refs/heads/main/deno.svg" align="top" width="18" height="21"> **Deno** <sup>[[docs](https://docs.deno.com/api/deno/~/Deno.createHttpClient)]</sup>
641
+
642
+ ```ts
643
+ import NotDiamond from 'npm:notdiamond';
644
+
645
+ const httpClient = Deno.createHttpClient({ proxy: { url: 'http://localhost:8888' } });
646
+ const client = new NotDiamond({
647
+ fetchOptions: {
648
+ client: httpClient,
649
+ },
650
+ });
119
651
  ```
120
652
 
121
- ## API Reference
653
+ ## Frequently Asked Questions
654
+
655
+ ## Semantic versioning
656
+
657
+ This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
658
+
659
+ 1. Changes that only affect static types, without breaking runtime behavior.
660
+ 2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_
661
+ 3. Changes that we do not expect to impact the vast majority of users in practice.
662
+
663
+ We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
122
664
 
123
- For a complete API reference and more detailed documentation, please check our [API Documentation](https://notdiamond.readme.io/docs/what-is-not-diamond#getting-started).
665
+ We are keen for your feedback; please open an [issue](https://www.github.com/Not-Diamond/not-diamond-typescript/issues) with questions, bugs, or suggestions.
124
666
 
125
- ## Key Concepts
667
+ ## Requirements
126
668
 
127
- - **llmProviders**: An array of AI providers and models you want NotDiamond to choose from.
128
- - **tradeoff**: The factor to optimize for (e.g., 'latency', 'cost', 'performance').
129
- - **tools**: Custom functions that the AI can use to perform specific tasks.
130
- - **maxModelDepth**: The maximum number of models to include in the response (for advanced use cases).
669
+ TypeScript >= 4.9 is supported.
131
670
 
132
- ## Error Handling
671
+ The following runtimes are supported:
133
672
 
134
- NotDiamond uses typed responses. If there's an error, the response will have a `detail` property with the error message. Always check for this property when handling responses.
673
+ - Web browsers (Up-to-date Chrome, Firefox, Safari, Edge, and more)
674
+ - Node.js 20 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
675
+ - Deno v1.28.0 or higher.
676
+ - Bun 1.0 or later.
677
+ - Cloudflare Workers.
678
+ - Vercel Edge Runtime.
679
+ - Jest 28 or greater with the `"node"` environment (`"jsdom"` is not supported at this time).
680
+ - Nitro v2.6 or greater.
135
681
 
136
- ## Support
682
+ Note that React Native is not supported at this time.
137
683
 
138
- If you encounter any issues or have questions, please [open an issue](https://github.com/Not-Diamond/notdiamond-node) on our GitHub repository.
684
+ If you are interested in other runtime environments, please open or upvote an issue on GitHub.
139
685
 
140
- ## License
686
+ ## Contributing
141
687
 
142
- This library is released under the MIT License.
688
+ See [the contributing documentation](./CONTRIBUTING.md).