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