Open History to see the last commit
1import { afterEach, describe, expect, it } from 'vitest'
2
3import {
4 parsePerplexityModelsPage,
5 parsePerplexityPresets,
6 provider,
7} from './perplexity.ts'
8
9const MODELS_URL = 'https://api.perplexity.ai/v1/models'
10const DOC_URL = 'https://docs.perplexity.ai/docs/agent-api/models.md'
11const PRESETS_URL = 'https://docs.perplexity.ai/docs/agent-api/presets.md'
12
13const HEADER = [
14 '| Model | Input (\\$/1M) | Output (\\$/1M) | Cache read (\\$/1M) | Service tiers | Docs |',
15 '| - | - | - | - | - | - |',
16]
17
18// Five tabs of the Agent API models page, as served on 2026-10-07, in the
19// markdown export's shape since 2026-10-20: a bold tab title, the card as
20// a `> **Title**` blockquote, the table, and the effort note as a
21// `> [!NOTE]` callout.
22const MODELS_DOC = [
23 '## Available Models',
24 '',
25 '**xAI**',
26 '',
27 '> **xAI**',
28 '>',
29 '> Grok 4.7, 4.6, 4.5, 4.3, and 4.20 variants: flagship, reasoning, non-reasoning, and multi-agent.',
30 '',
31 ...HEADER,
32 '| `xai/grok-4.20-non-reasoning` | 1.25 (\\<200k)<br />2.50 (≥200k) | 2.50 (\\<200k)<br />5.00 (≥200k) | 0.20 | — | [Grok 4.20 Non Reasoning](https://docs.x.ai/developers/models) |',
33 '',
34 '**Z.AI**',
35 '',
36 '> **Z.AI**',
37 '>',
38 '> GLM 5.3 and GLM 5.3 Flash — Z.AI reasoning models.',
39 '',
40 ...HEADER,
41 '| `perplexity/glm-5.3` | 1.40 | 4.40 | 0.26 | — | [GLM](https://docs.z.ai) |',
42 '| `perplexity/glm-5.3-flash` | 0.15 | 0.50 | 0.03 | — | [GLM-5.3 Flash](https://huggingface.co/zai-org/GLM-5.3-Flash) |',
43 '',
44 '**Moonshot AI**',
45 '',
46 '> **Moonshot AI**',
47 '>',
48 "> Kimi K3 — Moonshot AI's flagship reasoning model.",
49 '',
50 ...HEADER,
51 '| `perplexity/kimi-k3` | 3.00 | 15.00 | 0.30 | — | [Kimi K3](https://huggingface.co/moonshotai/Kimi-K3) |',
52 '',
53 '> [!NOTE]',
54 '>',
55 '> Kimi K3 accepts `minimal`, `low`, `medium`, `high`, `xhigh`, and `max` reasoning effort. `minimal` uses low effort, while `xhigh` and `max` use maximum effort. Reasoning tokens are billed at the output-token rate.',
56 '',
57 '**NVIDIA**',
58 '',
59 '> **NVIDIA**',
60 '>',
61 '> Nemotron 3 Ultra is an open-weight reasoning model.',
62 '',
63 ...HEADER,
64 '| `perplexity/nemotron-3-ultra-550b-a55b` | 0.25 | 2.50 | 0.25 | — | [Nemotron 3 Ultra](https://huggingface.co/nvidia/NVIDIA-Nemotron-3-Ultra-550B-A55B-BF16) |',
65 '',
66 '**Perplexity**',
67 '',
68 '> **Perplexity**',
69 '>',
70 "> Perplexity's grounded search model.",
71 '',
72 ...HEADER,
73 '| `perplexity/sonar` | 0.25 | 2.50 | 0.0625 | — | — |',
74 '',
75 '## Service tiers',
76 '',
77 '> [!WARNING]',
78 '>',
79 '> Not all third-party models support all features (e.g., reasoning, tools). Check model documentation for specific capabilities.',
80].join('\n')
81
82const KIMI_SENTENCE =
83 'Kimi K3 accepts `minimal`, `low`, `medium`, `high`, `xhigh`, and `max` reasoning effort.'
84
85describe('parsePerplexityModelsPage', () => {
86 it('reads the effort sentence and the reasoning-model cards', () => {
87 const page = parsePerplexityModelsPage(MODELS_DOC)
88 expect([...page.flags]).toEqual([
89 ['perplexity/glm-5.3', ['reasoning']],
90 ['perplexity/glm-5.3-flash', ['reasoning']],
91 ['perplexity/kimi-k3', ['reasoning', 'reasoning_effort']],
92 ['perplexity/nemotron-3-ultra-550b-a55b', ['reasoning']],
93 ])
94 expect([...page.efforts]).toEqual([
95 [
96 'perplexity/kimi-k3',
97 ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'],
98 ],
99 ])
100 })
101
102 it('reads a reasoning-model card that goes on to state other facts', () => {
103 // The NVIDIA tab as served on 2026-10-15.
104 const nvidia = MODELS_DOC.replace(
105 /^> Nemotron 3 Ultra[^]*?(?=\*\*Perplexity\*\*)/m,
106 [
107 '> Nemotron 3.5 Super is a reasoning model with a 1,048,576-token context window and up to 131,072 output tokens. It accepts text input only.',
108 '',
109 ...HEADER,
110 '| `perplexity/nemotron-3.5-super-120b-a12b` | 0.20 | 0.50 | 0.04 | — | — |',
111 '',
112 '',
113 ].join('\n'),
114 )
115 expect(nvidia).not.toBe(MODELS_DOC)
116 const page = parsePerplexityModelsPage(nvidia)
117 expect(page.flags.get('perplexity/nemotron-3.5-super-120b-a12b')).toEqual([
118 'reasoning',
119 ])
120 expect(page.flags.has('perplexity/nemotron-3-ultra-550b-a55b')).toBe(false)
121 // The same sentence's limits are that model's, and no other row's.
122 expect([...page.limits]).toEqual([
123 [
124 'perplexity/nemotron-3.5-super-120b-a12b',
125 { contextWindow: 1_048_576, maxOutput: 131_072 },
126 ],
127 ])
128 })
129
130 it('leaves the effort flag off when no tab states an effort', () => {
131 const silent = MODELS_DOC.replace(
132 /^> \[!NOTE\]\n>\n> Kimi K3[^\n]*\n\n/m,
133 '',
134 )
135 const page = parsePerplexityModelsPage(silent)
136 expect(page.flags.get('perplexity/kimi-k3')).toEqual(['reasoning'])
137 expect(page.efforts.size).toBe(0)
138 })
139
140 it.each([
141 ['a reworded sentence', 'Kimi K3 accepts', 'Kimi K3 supports'],
142 [
143 'a list with prose in it',
144 '`xhigh`, and `max`',
145 '`xhigh`, and up to `max`',
146 ],
147 ['a name no row carries', 'Kimi K3 accepts', 'Kimi K4 accepts'],
148 [
149 'a second, unread mention',
150 'output-token rate.',
151 'output-token rate.\n>\n> GLM takes any reasoning effort.',
152 ],
153 [
154 'a second sentence for the same model',
155 'output-token rate.',
156 'output-token rate.\n>\n> Kimi K3 accepts `low` and `high` reasoning effort.',
157 ],
158 [
159 'the sentence moved outside the tabs',
160 /^> \[!NOTE\]\n>\n> Kimi K3 accepts[^\n]*\n\n([^]*?## Service tiers\n)/m,
161 `$1\n${KIMI_SENTENCE}\n`,
162 ],
163 [
164 'a statement that reasoning cannot be disabled',
165 'reasoning effort. `minimal`',
166 'reasoning effort. Reasoning cannot be disabled. `minimal`',
167 ],
168 [
169 'a statement that the model always thinks',
170 "Kimi K3 — Moonshot AI's flagship reasoning model.",
171 "Kimi K3 — Moonshot AI's flagship always-on reasoning model.",
172 ],
173 [
174 'a card naming fewer models than its tab lists',
175 'GLM 5.3 and GLM 5.3 Flash — Z.AI',
176 'GLM 5.3 — Z.AI',
177 ],
178 [
179 'a card that denies it',
180 'is an open-weight reasoning model',
181 'is not a reasoning model',
182 ],
183 [
184 'a reworded card',
185 'is an open-weight reasoning model.',
186 'ranks among open reasoning models, in our tests.',
187 ],
188 [
189 'a card with a second sentence on reasoning models',
190 'is an open-weight reasoning model.',
191 'is an open-weight reasoning model. It replaces our older reasoning models.',
192 ],
193 [
194 'a second card sentence on thinking',
195 'is an open-weight reasoning model.',
196 'is an open-weight reasoning model. You cannot turn its thinking off.',
197 ],
198 [
199 'a "with" clause on reasoning',
200 'is an open-weight reasoning model.',
201 'is an open-weight reasoning model with reasoning off by default.',
202 ],
203 [
204 'a "with" clause on whether thinking can be skipped',
205 'is an open-weight reasoning model.',
206 'is an open-weight reasoning model with a mandatory chain-of-thought.',
207 ],
208 [
209 'a "with" clause in another shape',
210 'is an open-weight reasoning model.',
211 'is an open-weight reasoning model with a chain-of-thought you cannot skip.',
212 ],
213 ['a card titled for another tab', '> **NVIDIA**', '> **Nemotron**'],
214 ['a card with no spacer line', '> **Z.AI**\n>\n', '> **Z.AI**\n'],
215 ['a tab title in another shape', '**Z.AI**\n', '**Z.AI** \n'],
216 [
217 'a card split by a blank line',
218 '> Nemotron 3 Ultra is',
219 '> NVIDIA Nemotron.\n\n> Nemotron 3 Ultra is',
220 ],
221 ['a table before the first tab title', '**xAI**\n\n', ''],
222 [
223 'a card that goes on with a clause other than "with"',
224 'is an open-weight reasoning model.',
225 'is an open-weight reasoning model for agents.',
226 ],
227 ])('throws on %s', (_case, from, to) => {
228 const mutated = MODELS_DOC.replace(from, to)
229 expect(mutated).not.toBe(MODELS_DOC)
230 expect(() => parsePerplexityModelsPage(mutated)).toThrow('unread shape')
231 })
232
233 it('reads only the Available Models section', () => {
234 const later = `${MODELS_DOC}\n\n**Extra**\n\n> **Extra**\n>\n> Extra is a reasoning model.\n\n${HEADER.join('\n')}\n| \`perplexity/extra\` | 1 | 1 | 1 | — | — |\n`
235 expect(parsePerplexityModelsPage(later).flags.has('perplexity/extra')).toBe(
236 false,
237 )
238 })
239
240 it('throws on a page with no model table, such as an HTML error page', () => {
241 expect(() => parsePerplexityModelsPage('<html>Not found</html>')).toThrow(
242 'lists no models',
243 )
244 })
245})
246
247// Three of the five presets as served on 2026-10-07, in the markdown
248// export's shape since 2026-10-20: each accordion is one blockquote.
249// Bullets are trimmed, and only `fast` keeps its prompt block, cut to one
250// `## ` heading; the real blocks also hold SDK code samples.
251const PRESETS_DOC = [
252 '## Current preset values',
253 '',
254 '> **fast — current preset values**',
255 '>',
256 '> Quick factual lookups with minimal latency and inline citations for search-backed claims.',
257 '>',
258 '> * **Model:** `openai/gpt-6-luna`',
259 '> * **Prompt cache key:** `fast`',
260 '> * **Max steps:** 1',
261 '> * **Reasoning effort:** `none`',
262 '> * **Service tier:** `priority`',
263 '> * **Max output tokens:** 8192',
264 '> * **Tools:** `web_search`',
265 '> * **System prompt:** included inline below',
266 '>',
267 '> ```text',
268 '> ## Role',
269 '> ```',
270 '',
271 '> **low — current preset values**',
272 '>',
273 '> * **Model:** `openai/gpt-6-luna`',
274 '> * **Reasoning effort:** `minimal`',
275 '> * **Tools:** `web_search`, `fetch_url` (`max_urls: 1`)',
276 '',
277 '> **xhigh — current preset values**',
278 '>',
279 '> * **Model:** `anthropic/claude-opus-5-5`',
280 '> * **Max steps:** 100',
281 '> * **Reasoning effort:** `high`',
282 '> * **Tools:** `web_search`, `finance_search`, `sandbox`',
283 '',
284 '## Next Steps',
285 '',
286 '> **[Agent API Models](/docs/agent-api/models)**',
287].join('\n')
288
289describe('parsePerplexityPresets', () => {
290 it('reads each preset model with the effort and tools it runs with', () => {
291 expect([...parsePerplexityPresets(PRESETS_DOC)]).toEqual([
292 ['openai/gpt-6-luna', ['reasoning', 'reasoning_effort', 'tools']],
293 ['anthropic/claude-opus-5-5', ['reasoning', 'reasoning_effort', 'tools']],
294 ])
295 })
296
297 it('gives a preset with no tools or effort bullet neither flag', () => {
298 const bare = PRESETS_DOC.replace(
299 '> * **Reasoning effort:** `high`\n> * **Tools:** `web_search`, `finance_search`, `sandbox`\n',
300 '',
301 )
302 expect(parsePerplexityPresets(bare).has('anthropic/claude-opus-5-5')).toBe(
303 false,
304 )
305 })
306
307 it.each([
308 [
309 'a preset with no model bullet',
310 '* **Model:** `openai',
311 '* **LLM:** `openai',
312 ],
313 ['a model that is prose', '`anthropic/claude-opus-5-5`', 'Claude Opus 5.5'],
314 ['an effort that is prose', '`high`', 'high, or lower on retries'],
315 [
316 'tools that are prose',
317 '`web_search`, `finance_search`, `sandbox`',
318 'none',
319 ],
320 [
321 'a bullet stated twice',
322 '> * **Max steps:** 100',
323 '> * **Model:** `openai/gpt-6-sol`',
324 ],
325 ['a page with no preset accordions', / — current preset values/g, ''],
326 [
327 'an accordion split by a blank line',
328 '> * **Reasoning effort:** `high`\n',
329 '> * **Reasoning effort:** `high`\n\n',
330 ],
331 [
332 'an accordion title in another shape',
333 '> **xhigh — current preset values**',
334 '> **xhigh — current preset values (beta)**',
335 ],
336 ])('throws on %s', (_case, from, to) => {
337 const mutated = PRESETS_DOC.replace(from, to)
338 expect(mutated).not.toBe(PRESETS_DOC)
339 expect(() => parsePerplexityPresets(mutated)).toThrow('perplexity: preset')
340 })
341})
342
343const originalFetch = globalThis.fetch
344
345afterEach(() => {
346 globalThis.fetch = originalFetch
347})
348
349describe('perplexity provider', () => {
350 it('exports seed metadata for the isolation loader', () => {
351 expect(provider.id).toBe('perplexity')
352 expect(provider.displayName).toBe('Perplexity')
353 expect(provider.authEnvVar).toBe('PERPLEXITY_API_KEY')
354 expect(provider.defaultDerivation).toBe('upstream-spec')
355 expect(provider.specSourceUrl).toBe(
356 'https://docs.perplexity.ai/openapi.json',
357 )
358 expect(provider.modelsEndpoint).toBe('https://api.perplexity.ai/v1/models')
359 })
360
361 it('names the maker the id is namespaced under, and none for hosted ids', () => {
362 expect(
363 provider.upstreamModelIdentity?.('xai/grok-4.20-non-reasoning'),
364 ).toMatchObject({
365 providerNamespace: 'xai',
366 rawId: 'grok-4.20-non-reasoning',
367 source: { derivation: 'listing', path: 'data[].id' },
368 })
369 expect(provider.upstreamModelIdentity?.('perplexity/kimi-k3')).toBeNull()
370 expect(provider.upstreamModelIdentity?.('sonar')).toBeNull()
371 })
372})
373
374describe('perplexity classify', () => {
375 it('maps generation paths and drops search, async, and platform', () => {
376 expect(provider.classify('/v1/sonar', {})).toBe('chat')
377 expect(provider.classify('/v1/agent', {})).toBe('chat')
378 expect(provider.classify('/v1/embeddings', {})).toBe('embeddings')
379 expect(provider.classify('/v1/contextualizedembeddings', {})).toBe(
380 'embeddings',
381 )
382 expect(provider.classify('/search', {})).toBeNull()
383 expect(provider.classify('/v1/async/sonar', {})).toBeNull()
384 expect(provider.classify('/v1/models', {})).toBeNull()
385 expect(provider.classify('/v1/agent/{id}/cancel', {})).toBeNull()
386 expect(provider.classify('/v1/analytics/computer/usage', {})).toBeNull()
387 })
388})
389
390describe('perplexity listModels', () => {
391 it('skips when the secret is absent', async () => {
392 const result = await provider.listModels({})
393 expect(result.skipped).toBe(
394 'perplexity: PERPLEXITY_API_KEY not set — skipped',
395 )
396 expect(result.models).toEqual([])
397 })
398
399 it('joins the listing to the flags both docs pages state', async () => {
400 const urls: Array<string> = []
401 globalThis.fetch = ((url: string, init?: RequestInit) => {
402 urls.push(String(url))
403 expect(init?.signal).toBeInstanceOf(AbortSignal)
404 if (String(url) === DOC_URL) {
405 return Promise.resolve(new Response(MODELS_DOC))
406 }
407 if (String(url) === PRESETS_URL) {
408 return Promise.resolve(new Response(PRESETS_DOC))
409 }
410 expect(
411 new Headers(init?.headers).get('Authorization')?.startsWith('Bearer '),
412 ).toBe(true)
413 return Promise.resolve(
414 Response.json({
415 object: 'list',
416 data: [
417 { id: 'perplexity/kimi-k3', created: 1 },
418 { id: 'perplexity/sonar', created: 2 },
419 { id: 'openai/gpt-6-luna', created: 3 },
420 { id: 'xai/grok-4.20-non-reasoning', created: 4 },
421 ],
422 }),
423 )
424 }) as typeof fetch
425
426 const result = await provider.listModels({
427 PERPLEXITY_API_KEY: 'test-key',
428 })
429 expect(urls.sort()).toEqual([MODELS_URL, DOC_URL, PRESETS_URL])
430 expect(result.skipped).toBeUndefined()
431 const source = (sourceUrl: string, path: string) => ({
432 derivation: 'docs-derived',
433 sourceUrl,
434 sourceHash: expect.stringMatching(/^[0-9a-f]{64}$/) as string,
435 path,
436 })
437 expect(result.models).toEqual([
438 {
439 rawId: 'perplexity/kimi-k3',
440 releasedAt: 1,
441 activity: 'chat',
442 capabilities: ['reasoning', 'reasoning_effort'],
443 // The page publishes the levels and is silent on turning it off.
444 reasoning: {
445 mode: 'effort',
446 mandatory: null,
447 efforts: ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'],
448 },
449 factSources: {
450 reasoning: source(DOC_URL, 'reasoning_effort'),
451 capabilities: {
452 reasoning: source(DOC_URL, 'reasoning'),
453 reasoning_effort: source(DOC_URL, 'reasoning_effort'),
454 },
455 },
456 },
457 { rawId: 'perplexity/sonar', releasedAt: 2, activity: 'chat' },
458 {
459 rawId: 'openai/gpt-6-luna',
460 releasedAt: 3,
461 activity: 'chat',
462 capabilities: ['reasoning', 'reasoning_effort', 'tools'],
463 factSources: {
464 capabilities: {
465 reasoning: source(PRESETS_URL, 'reasoning'),
466 reasoning_effort: source(PRESETS_URL, 'reasoning_effort'),
467 tools: source(PRESETS_URL, 'tools'),
468 },
469 },
470 },
471 { rawId: 'xai/grok-4.20-non-reasoning', releasedAt: 4, activity: 'chat' },
472 ])
473 // Only the row whose effort list the models page states gets `reasoning`.
474 expect(result.models.filter((model) => model.reasoning != null)).toEqual([
475 expect.objectContaining({ rawId: 'perplexity/kimi-k3' }),
476 ])
477 expect(
478 provider.generationEndpointId?.({
479 rawId: 'perplexity/sonar',
480 activity: 'chat',
481 }),
482 ).toBe('v1/agent')
483 })
484
485 it('puts a card sentence’s limits on its own row only', async () => {
486 const nemotron = 'perplexity/nemotron-3.5-super-120b-a12b'
487 const nvidia = MODELS_DOC.replace(
488 /^> Nemotron 3 Ultra[^]*?(?=\*\*Perplexity\*\*)/m,
489 [
490 '> Nemotron 3.5 Super is a reasoning model with a 1,048,576-token context window and up to 131,072 output tokens. It accepts text input only.',
491 '',
492 ...HEADER,
493 `| \`${nemotron}\` | 0.20 | 0.50 | 0.04 | — | — |`,
494 '',
495 '',
496 ].join('\n'),
497 )
498 globalThis.fetch = ((url: string) =>
499 Promise.resolve(
500 String(url) === MODELS_URL
501 ? Response.json({
502 data: [{ id: nemotron }, { id: 'perplexity/sonar' }],
503 })
504 : new Response(String(url) === DOC_URL ? nvidia : PRESETS_DOC),
505 )) as typeof fetch
506 const { models } = await provider.listModels({
507 PERPLEXITY_API_KEY: 'test-key',
508 })
509 const row = models.find((m) => m.rawId === nemotron)
510 expect(row).toMatchObject({
511 contextWindow: 1_048_576,
512 maxOutput: 131_072,
513 factSources: {
514 contextWindow: { derivation: 'docs-derived', sourceUrl: DOC_URL },
515 maxOutput: { derivation: 'docs-derived', sourceUrl: DOC_URL },
516 },
517 })
518 expect(row?.factSources?.contextWindow?.sourceHash).toMatch(
519 /^[0-9a-f]{64}$/,
520 )
521 const sonar = models.find((m) => m.rawId === 'perplexity/sonar')
522 expect(sonar?.contextWindow).toBeUndefined()
523 expect(sonar?.factSources?.contextWindow).toBeUndefined()
524 })
525
526 it('reads an off value in the published list as "can be turned off"', async () => {
527 const withNone = MODELS_DOC.replace('accepts `minimal`,', 'accepts `none`,')
528 expect(withNone).not.toBe(MODELS_DOC)
529 globalThis.fetch = ((url: string) =>
530 Promise.resolve(
531 String(url) === MODELS_URL
532 ? Response.json({ data: [{ id: 'perplexity/kimi-k3' }] })
533 : new Response(String(url) === DOC_URL ? withNone : PRESETS_DOC),
534 )) as typeof fetch
535 const result = await provider.listModels({ PERPLEXITY_API_KEY: 'test-key' })
536 expect(result.models[0]?.reasoning).toEqual({
537 mode: 'effort',
538 mandatory: false,
539 efforts: ['none', 'low', 'medium', 'high', 'xhigh', 'max'],
540 })
541 })
542
543 it('still lists, and reports the page, when a docs page is an HTML error page', async () => {
544 globalThis.fetch = ((url: string) =>
545 Promise.resolve(
546 String(url) === MODELS_URL
547 ? Response.json({ data: [{ id: 'perplexity/sonar' }] })
548 : String(url) === DOC_URL
549 ? new Response(MODELS_DOC)
550 : new Response('<html>Not found</html>'),
551 )) as typeof fetch
552 // One page down withholds both pages' flags: half of them would read
553 // as the other half dropped.
554 expect(
555 await provider.listModels({ PERPLEXITY_API_KEY: 'test-key' }),
556 ).toEqual({
557 models: [
558 {
559 rawId: 'perplexity/sonar',
560 releasedAt: null,
561 activity: 'chat',
562 absent: {
563 capabilities: 'unavailable',
564 reasoning: 'unavailable',
565 contextWindow: 'unavailable',
566 maxOutput: 'unavailable',
567 },
568 },
569 ],
570 docsFailures: {
571 failed: 1,
572 skipped: 0,
573 first: [
574 {
575 source: PRESETS_URL,
576 error: 'perplexity: presets page lists no preset models',
577 elapsedMs: expect.any(Number) as number,
578 },
579 ],
580 },
581 })
582 })
583
584 it('fails the poll when the listing fails', async () => {
585 globalThis.fetch = ((url: string) =>
586 Promise.resolve(
587 String(url) === MODELS_URL
588 ? new Response('down', { status: 503 })
589 : new Response(String(url) === DOC_URL ? MODELS_DOC : PRESETS_DOC),
590 )) as typeof fetch
591 await expect(
592 provider.listModels({ PERPLEXITY_API_KEY: 'test-key' }),
593 ).rejects.toThrow('503')
594 })
595})
596
597describe('perplexity fetchSpec', () => {
598 it('loads the published OpenAPI document without a key', async () => {
599 const spec = {
600 openapi: '3.1.0',
601 info: { title: 'Perplexity AI API' },
602 paths: { '/v1/sonar': { post: { summary: 'Create Chat Completion' } } },
603 }
604 globalThis.fetch = ((url: string) => {
605 expect(String(url)).toBe('https://docs.perplexity.ai/openapi.json')
606 return Promise.resolve(new Response(JSON.stringify(spec)))
607 }) as typeof fetch
608
609 const fetched = await provider.fetchSpec({})
610 expect(fetched.specs).toHaveLength(1)
611 expect(fetched.specs[0]?.info?.title).toBe('Perplexity AI API')
612 expect(fetched.sources[0]?.url).toBe(
613 'https://docs.perplexity.ai/openapi.json',
614 )
615 expect(fetched.sources[0]?.hash).toMatch(/^[0-9a-f]{64}$/)
616 expect(fetched.outputStrategy).toBe('post-200')
617 })
618})