Open History to see the last commit
1import selectorSources from './fixtures/nvidia-native-selector-identity.json'
2import { describe, expect, it } from 'vitest'
3
4import {
5 nvidiaInferNamesModel,
6 nvidiaMaxOutput,
7 nvidiaModelSpec,
8 nvidiaReasoning,
9 parseNvidiaInfer,
10 parseNvidiaReferenceIndex,
11} from './nvidia-openapi.ts'
12
13/** Excerpt of https://docs.api.nvidia.com/nim/reference/llm-apis.md (2026-10-07). */
14const INDEX = `---
15updatedAt: 2026-10-05T22:07:01.000Z
16---
17
18| Model | Endpoint |
19| --- | --- |
20| [deepseek-ai / deepseek-v4-flash](https://docs.api.nvidia.com/nim/reference/deepseek-ai-deepseek-v4-flash) | [chat](https://docs.api.nvidia.com/nim/reference/deepseek-ai-deepseek-v4-flash-infer) |
21| [moonshot ai / kimi-k2.6](https://docs.api.nvidia.com/nim/reference/moonshotai-kimi-k2-6) | [chat](https://docs.api.nvidia.com/nim/reference/moonshotai-kimi-k2-6-infer) |
22| [z-ai / glm-5.2](ref:z-ai-glm-5.2) | [chat](ref:z-ai-glm-5.2-infer) |
23| [snowflake / arctic-embed-l](https://docs.api.nvidia.com/nim/reference/snowflake-arctic-embed-l) | [status](https://docs.api.nvidia.com/nim/reference/snowflake-arctic-embed-l-statuspolling) |
24| [nvidia / nemotron-3-nano-omni-30b-a3b-reasoning](https://docs.api.nvidia.com/nim/reference/nvidia-nemotron-3-nano-omni-30b-a3b-reasoning) | [chat](https://docs.api.nvidia.com/nim/reference/nvidia-nemotron-3-nano-omni-30b-a3b-reasoning) |
25`
26
27function inferDoc(
28 properties: Record<string, unknown>,
29 path = '/chat/completions',
30 title = 'NVIDIA NIM API',
31): string {
32 return `# OpenAPI definition
33
34\`\`\`json
35${JSON.stringify({
36 openapi: '3.1.0',
37 info: { title },
38 paths: {
39 [path]: {
40 post: {
41 requestBody: {
42 content: {
43 'application/json': {
44 schema: { type: 'object', properties },
45 },
46 },
47 },
48 },
49 },
50 },
51})}
52\`\`\`
53`
54}
55
56describe('parseNvidiaReferenceIndex', () => {
57 it('reads listing ids and infer links, including ref: rows', () => {
58 expect(parseNvidiaReferenceIndex(INDEX)).toEqual([
59 {
60 rawId: 'deepseek-ai/deepseek-v4-flash',
61 inferUrl:
62 'https://docs.api.nvidia.com/nim/reference/deepseek-ai-deepseek-v4-flash-infer',
63 },
64 {
65 rawId: 'moonshotai/kimi-k2.6',
66 inferUrl:
67 'https://docs.api.nvidia.com/nim/reference/moonshotai-kimi-k2-6-infer',
68 },
69 {
70 rawId: 'z-ai/glm-5.2',
71 inferUrl:
72 'https://docs.api.nvidia.com/nim/reference/z-ai-glm-5.2-infer',
73 },
74 {
75 rawId: 'nvidia/nemotron-3-nano-omni-30b-a3b-reasoning',
76 inferUrl:
77 'https://docs.api.nvidia.com/nim/reference/nvidia-nemotron-3-nano-omni-30b-a3b-reasoning-infer',
78 },
79 ])
80 })
81
82 it('throws when the page is not a reference index', () => {
83 expect(() =>
84 parseNvidiaReferenceIndex('<html>Just a moment</html>'),
85 ).toThrow('not markdown')
86 })
87})
88
89describe('nvidiaInferNamesModel', () => {
90 const nano = 'nvidia/nemotron-3-nano-omni-30b-a3b-reasoning'
91 const safety = 'nvidia/nemotron-3.5-content-safety'
92
93 it('accepts a document that names this model, and one that names none', () => {
94 const named = parseNvidiaInfer(
95 inferDoc(
96 { model: { type: 'string', default: nano } },
97 '/chat/completions',
98 nano,
99 ),
100 )
101 const unnamed = parseNvidiaInfer(
102 inferDoc({
103 max_tokens: {
104 type: 'integer',
105 maximum: 8192,
106 description: 'The maximum number of tokens to generate.',
107 },
108 }),
109 )
110 expect(named && nvidiaInferNamesModel(nano, named.document)).toBe(true)
111 expect(unnamed && nvidiaInferNamesModel(safety, unnamed.document)).toBe(
112 true,
113 )
114 })
115
116 it('rejects the nano document embedded on the content-safety page', () => {
117 const facts = parseNvidiaInfer(
118 inferDoc(
119 {
120 model: { type: 'string', default: nano },
121 max_tokens: {
122 type: 'integer',
123 maximum: 65536,
124 description: 'The maximum number of tokens to generate.',
125 },
126 reasoning_budget: { type: 'integer', maximum: 32768 },
127 },
128 '/chat/completions',
129 nano,
130 ),
131 )
132 expect(facts && nvidiaInferNamesModel(safety, facts.document)).toBe(false)
133 expect(facts && nvidiaInferNamesModel(nano, facts.document)).toBe(true)
134 })
135})
136
137describe('parseNvidiaInfer', () => {
138 it('reads an anyOf max_tokens cap and an effort enum', () => {
139 const facts = parseNvidiaInfer(
140 inferDoc({
141 max_tokens: {
142 anyOf: [
143 { type: 'integer', maximum: 65536, minimum: 1 },
144 { type: 'null' },
145 ],
146 description: 'The maximum number of tokens that can be generated.',
147 },
148 reasoning_effort: { enum: ['low', 'high', 'max'], default: 'max' },
149 }),
150 )
151 expect(facts).toMatchObject({
152 activity: 'chat',
153 maxOutput: 65536,
154 reasoning: {
155 mode: 'effort',
156 mandatory: null,
157 efforts: ['low', 'high', 'max'],
158 },
159 })
160 })
161
162 it('reads a reasoning budget and an off effort', () => {
163 expect(
164 nvidiaReasoning(
165 parseNvidiaInfer(
166 inferDoc({
167 reasoning_budget: {
168 type: 'integer',
169 maximum: 32768,
170 minimum: -1,
171 description: 'Use -1 to disable budget enforcement.',
172 },
173 max_tokens: {
174 type: 'integer',
175 maximum: 32768,
176 description: 'The maximum number of tokens to generate.',
177 },
178 }),
179 )!.document,
180 ),
181 ).toEqual({ mode: 'budget', mandatory: null })
182 expect(
183 nvidiaReasoning(
184 parseNvidiaInfer(
185 inferDoc({
186 reasoning_effort: { enum: ['none', 'high', 'max'] },
187 }),
188 )!.document,
189 ),
190 ).toEqual({
191 mode: 'effort',
192 mandatory: null,
193 efforts: ['none', 'high', 'max'],
194 })
195 })
196
197 it('reads a chat_template_kwargs description that states thinking on and off', () => {
198 expect(
199 nvidiaReasoning(
200 parseNvidiaInfer(
201 inferDoc({
202 chat_template_kwargs: {
203 anyOf: [{ type: 'object' }, { type: 'null' }],
204 description:
205 'Optional kwargs forwarded to the model chat template (e.g. {"thinking": true} / {"thinking": false}).',
206 },
207 }),
208 )!.document,
209 ),
210 ).toEqual({ mode: 'toggle', mandatory: false })
211 })
212
213 it('follows a component ref for max_tokens', () => {
214 const markdown = `# OpenAPI definition
215
216\`\`\`json
217${JSON.stringify({
218 openapi: '3.1.0',
219 paths: {
220 '/chat/completions': {
221 post: {
222 requestBody: {
223 content: {
224 'application/json': {
225 schema: { $ref: '#/components/schemas/Request' },
226 },
227 },
228 },
229 },
230 },
231 },
232 components: {
233 schemas: {
234 Request: {
235 type: 'object',
236 properties: {
237 max_tokens: {
238 type: 'integer',
239 maximum: 4096,
240 description: 'The maximum number of tokens to generate.',
241 },
242 },
243 },
244 },
245 },
246})}
247\`\`\`
248`
249 const facts = parseNvidiaInfer(markdown)
250 expect(nvidiaMaxOutput(facts!.document)).toBe(4096)
251 expect(nvidiaModelSpec('openai/gpt-oss-20b', facts!)?.paths).toHaveProperty(
252 '/chat/completions',
253 )
254 })
255
256 it('returns null when the page has no OpenAPI document', () => {
257 expect(parseNvidiaInfer('# Model\n\n```json\n"not a spec"\n```')).toBeNull()
258 })
259})
260
261it('rejects conflicting native const/default/enum model selectors despite matching API title', () => {
262 for (const selector of [
263 { const: 'nvidia/wrong', default: 'nvidia/right' },
264 { enum: ['nvidia/right', 'nvidia/wrong'], default: 'nvidia/right' },
265 { allOf: [{ const: 'nvidia/wrong' }, { default: 'nvidia/right' }] },
266 ]) {
267 const facts = parseNvidiaInfer(
268 inferDoc({ model: selector }, '/chat/completions', 'nvidia/right'),
269 )
270 expect(facts && nvidiaInferNamesModel('nvidia/right', facts.document)).toBe(
271 false,
272 )
273 }
274})
275
276it('uses actual native ReadMe request identities while retaining the API display titles', () => {
277 const guard = parseNvidiaInfer(
278 selectorSources[
279 'https://docs.api.nvidia.com/nim/reference/nvidia-llama-3_1-nemotron-safety-guard-8b-v3-infer.md'
280 ].body,
281 )
282 const parse = parseNvidiaInfer(
283 selectorSources[
284 'https://docs.api.nvidia.com/nim/reference/nvidia-nemotron-parse-2_0-infer.md'
285 ].body,
286 )
287 const safety = parseNvidiaInfer(
288 selectorSources[
289 'https://docs.api.nvidia.com/nim/reference/nvidia-nemotron-3-5-content-safety-infer.md'
290 ].body,
291 )
292 expect(guard?.document.info?.title).toContain('llama-3_1')
293 expect(
294 guard &&
295 nvidiaInferNamesModel(
296 'nvidia/llama-3.1-nemotron-safety-guard-8b-v3',
297 guard.document,
298 ),
299 ).toBe(true)
300 expect(parse?.document.info?.title).toBe(
301 'NVIDIA NIM API for nvidia/nemotron-parse',
302 )
303 expect(
304 parse && nvidiaInferNamesModel('nvidia/nemotron-parse-2.0', parse.document),
305 ).toBe(true)
306 expect(
307 safety &&
308 nvidiaInferNamesModel(
309 'nvidia/nemotron-3.5-content-safety',
310 safety.document,
311 ),
312 ).toBe(false)
313})