7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.
TypeScript
feat(search): Parallel as a keyless web search engine (#1465)
George Pickett08a7100d9907
diff --git a/client/src/components/command-palette.tsx b/client/src/components/command-palette.tsxindex 81d9b375..bbd03efa 100644--- a/client/src/components/command-palette.tsx+++ b/client/src/components/command-palette.tsx@@ -112,7 +112,7 @@ export function CommandPalette() {{ id: 'p-image', group: 'pages', label: t('models.imageTab'), keywords: 'models image generation', icon: ImageIcon, run: go('/models/image') },{ id: 'p-video', group: 'pages', label: t('models.videoTab'), keywords: 'models video text to video generation mp4', icon: Clapperboard, run: go('/models/video') },{ id: 'p-audio', group: 'pages', label: t('models.audioTab'), keywords: 'models audio speech tts stt transcription whisper', icon: AudioLines, run: go('/models/audio') },- { id: 'p-search', group: 'pages', label: t('search.tab'), keywords: 'models search web tavily exa firecrawl linkup', icon: Globe, run: go('/models/search') },+ { id: 'p-search', group: 'pages', label: t('search.tab'), keywords: 'models search web tavily exa firecrawl linkup parallel', icon: Globe, run: go('/models/search') },{ id: 'p-fusion', group: 'pages', label: t('models.fusionTab'), keywords: 'models fusion synthesis panel judge', icon: Zap, run: go('/models/fusion') },{ id: 'p-playground', group: 'pages', label: t('nav.playground'), keywords: 'playground test chat try', icon: SquareTerminal, run: go('/playground') },{ id: 'p-keys', group: 'pages', label: t('nav.keys'), keywords: 'keys providers api tokens', icon: KeyRound, run: go('/keys') },diff --git a/client/src/components/keys/add-key-form.tsx b/client/src/components/keys/add-key-form.tsxindex 9e975d1c..ad3856ec 100644--- a/client/src/components/keys/add-key-form.tsx+++ b/client/src/components/keys/add-key-form.tsx@@ -147,7 +147,7 @@ export function AddKeyForm({ onSuccess, initialPlatform }: { onSuccess: (offer?:const needsAccountId = platform === 'cloudflare'// Key-optional providers (Kilo, OVH, AI Horde) work anonymously, but accept a// real key too (#1331): the field stays editable and may be left blank.- const isKeyless = PLATFORMS.find(p => p.value === platform)?.keyless ?? false+ const isKeyless = [...SEARCH_PROVIDERS, ...PLATFORMS].find(p => p.value === platform)?.keyless ?? false// Cloudflare pairs each token with an account id, and a key-optional// provider keeps a single anonymous row, so neither takes a list.const canPasteSeveral = !isKeyless && !needsAccountIddiff --git a/client/src/lib/routing.ts b/client/src/lib/routing.tsindex cb487112..4717a243 100644--- a/client/src/lib/routing.ts+++ b/client/src/lib/routing.ts@@ -464,6 +464,7 @@ export const platformColors: Record<string, string> = {exa: '#2563eb',firecrawl: '#ef4444',linkup: '#10b981',+ parallel: '#0ea5e9',}// ── Grouped (unified) rendering ──────────────────────────────────────────────diff --git a/client/src/lib/search.ts b/client/src/lib/search.tsindex 45b73d37..a7739a8d 100644--- a/client/src/lib/search.ts+++ b/client/src/lib/search.ts@@ -8,7 +8,7 @@ import type { SearchPlatform as SharedSearchPlatform } from '@freellmapi/shared/// Mirrors SEARCH_PLATFORMS in shared/types.ts. The client only imports types// from shared, so the list is repeated here; the two assertions below fail the// typecheck if either side gains a platform the other lacks.-export const SEARCH_PLATFORMS = ['tavily', 'exa', 'firecrawl', 'linkup'] as const+export const SEARCH_PLATFORMS = ['tavily', 'exa', 'firecrawl', 'linkup', 'parallel'] as constexport type SearchPlatform = (typeof SEARCH_PLATFORMS)[number]const sharedCoversClient: SharedSearchPlatform = '' as SearchPlatformconst clientCoversShared: SearchPlatform = '' as SharedSearchPlatform@@ -20,12 +20,14 @@ export function isSearchPlatform(platform: string): platform is SearchPlatform {}// Same shape and job as PLATFORMS in components/keys/shared.tsx: the label-// names the free allowance, `url` is where the key is created.-export const SEARCH_PROVIDERS: { value: SearchPlatform; label: string; url: string }[] = [+// names the free allowance, `url` is where the key is created, and `keyless`+// providers work with no key (a blank submit enables the anonymous tier).+export const SEARCH_PROVIDERS: { value: SearchPlatform; label: string; url: string; keyless?: boolean }[] = [{ value: 'tavily', label: 'Tavily (1,000 searches/month)', url: 'https://app.tavily.com/home' },{ value: 'exa', label: 'Exa ($10 search credits/month)', url: 'https://dashboard.exa.ai/api-keys' },{ value: 'firecrawl', label: 'Firecrawl (1,000 credits/month)', url: 'https://www.firecrawl.dev/app/api-keys' },{ value: 'linkup', label: 'Linkup (€5 credits/month)', url: 'https://app.linkup.so/api-keys' },+ { value: 'parallel', label: 'Parallel (no key needed)', url: 'https://platform.parallel.ai', keyless: true },]/** Short provider name for chips and badges ("Tavily", not the full label). */diff --git a/server/src/__tests__/providers/search-providers.test.ts b/server/src/__tests__/providers/search-providers.test.tsindex 4cfe842a..543d1a4a 100644--- a/server/src/__tests__/providers/search-providers.test.ts+++ b/server/src/__tests__/providers/search-providers.test.ts@@ -3,6 +3,7 @@ import { TavilyProvider } from '../../providers/tavily.js';import { ExaProvider } from '../../providers/exa.js';import { FirecrawlProvider } from '../../providers/firecrawl.js';import { LinkupProvider } from '../../providers/linkup.js';+import { ParallelProvider } from '../../providers/parallel.js';import { getProvider } from '../../providers/index.js';// Search platforms (#1174) validate keys without spending search credits and@@ -25,6 +26,7 @@ const cases = [{ provider: new ExaProvider(), url: 'https://api.exa.ai/search', method: 'POST' },{ provider: new FirecrawlProvider(), url: 'https://api.firecrawl.dev/v2/team/credit-usage', method: 'GET' },{ provider: new LinkupProvider(), url: 'https://api.linkup.so/v1/credits/balance', method: 'GET' },+ { provider: new ParallelProvider(), url: 'https://api.parallel.ai/v1/search', method: 'POST' },];describe.each(cases)('$provider.name key validation', ({ provider, url, method }) => {@@ -56,8 +58,31 @@ describe.each(cases)('$provider.name key validation', ({ provider, url, method }});});+describe('Parallel keyless validation', () => {+ it('is keyless', () => {+ expect(new ParallelProvider().keyless).toBe(true);+ });++ it('checks the stored sentinel with an MCP initialize, sending no key', async () => {+ const fn = respond(200);+ expect(await new ParallelProvider().validateKey('no-key')).toBe(true);+ const [calledUrl, init] = (fn.mock.calls as unknown as [string, RequestInit][])[0];+ expect(calledUrl).toBe('https://search.parallel.ai/mcp');+ expect(JSON.parse(init.body as string)).toMatchObject({ method: 'initialize' });+ expect((init.headers as Record<string, string>)['x-api-key']).toBeUndefined();+ });++ it('sends a real key as x-api-key with an empty body, which spends nothing', async () => {+ const fn = respond(422);+ expect(await new ParallelProvider().validateKey(' real-key ')).toBe(true);+ const [, init] = (fn.mock.calls as unknown as [string, RequestInit][])[0];+ expect((init.headers as Record<string, string>)['x-api-key']).toBe('real-key');+ expect(init.body).toBe('{}');+ });+});+describe('registry', () => {it('registers every search platform', () => {- for (const p of ['tavily', 'exa', 'firecrawl', 'linkup'] as const) expect(getProvider(p)?.platform).toBe(p);+ for (const p of ['tavily', 'exa', 'firecrawl', 'linkup', 'parallel'] as const) expect(getProvider(p)?.platform).toBe(p);});});diff --git a/server/src/__tests__/routes/keys.test.ts b/server/src/__tests__/routes/keys.test.tsindex 0992719c..41fb4ed5 100644--- a/server/src/__tests__/routes/keys.test.ts+++ b/server/src/__tests__/routes/keys.test.ts@@ -378,7 +378,7 @@ describe('Keys API', () => {expect(storedKey(created.id)).toBe('kilo-real-secret');});- it.each(['kilo', 'ovh', 'aihorde'])('POST /api/keys without a key stores one anonymous %s row', async (platform) => {+ it.each(['kilo', 'ovh', 'aihorde', 'parallel'])('POST /api/keys without a key stores one anonymous %s row', async (platform) => {const first = await request(app, 'POST', '/api/keys', { platform });const second = await request(app, 'POST', '/api/keys', { platform, key: ' ' });@@ -391,7 +391,7 @@ describe('Keys API', () => {expect(keys[0]).toMatchObject({ platform, keyless: true, keyOptional: true, exportable: false });});- it.each(['kilo', 'ovh', 'aihorde'])('POST /api/keys stores a real %s key encrypted', async (platform) => {+ it.each(['kilo', 'ovh', 'aihorde', 'parallel'])('POST /api/keys stores a real %s key encrypted', async (platform) => {const { status, body } = await request(app, 'POST', '/api/keys', { platform, key: ` ${platform}-secret-123 `, label: 'mine' });expect(status).toBe(201);diff --git a/server/src/__tests__/services/search.test.ts b/server/src/__tests__/services/search.test.tsindex 6ece8370..f876ecca 100644--- a/server/src/__tests__/services/search.test.ts+++ b/server/src/__tests__/services/search.test.ts@@ -134,6 +134,87 @@ describe('search service', () => {expect(out).toMatchObject({ answer: 'yes', provider: 'linkup', results: [{ title: 'S', url: 'https://s', content: 'src' }] });});+ describe('Parallel (keyless)', () => {+ function seedParallel(): void {+ getDb().prepare(`+ INSERT INTO media_models (platform, model_id, display_name, modality, priority, enabled, quota_label, meta_json)+ VALUES ('parallel', 'parallel-search', 'Parallel Search', 'search', 4, 1, 'Free, no key needed', '{}')+ `).run();+ }+ const mcpReply = (payload: unknown) => ({+ jsonrpc: '2.0',+ id: 1,+ result: { content: [{ type: 'text', text: JSON.stringify(payload) }] },+ });+ const hits = { results: [+ { url: 'https://a', title: 'A & B', excerpts: ['one', 'two'] },+ { url: 'https://b', title: null, excerpts: [] },+ { url: '', title: 'dropped', excerpts: ['x'] },+ ] };++ it('searches anonymously over MCP with the stored sentinel and maps excerpts', async () => {+ seedParallel();+ addKey('parallel', 'no-key');+ expect(searchAvailable()).toBe(true);+ const fn = mockFetch(() => json(mcpReply(hits)));+ const out = await runSearch('node version');+ const [url, init] = calls(fn)[0];+ expect(url).toBe('https://search.parallel.ai/mcp');+ expect((init.headers as Record<string, string>)['x-api-key']).toBeUndefined();+ const body = bodyOf(calls(fn)[0]);+ expect(body).toMatchObject({ method: 'tools/call', params: { name: 'web_search', arguments: { objective: 'node version', search_queries: ['node version'] } } });+ expect(body.params.arguments.session_id).toMatch(/^freellmapi-/);+ expect(out).toMatchObject({ provider: 'parallel', engine: 'parallel-search' });+ expect(out.results).toEqual([+ { title: 'A & B', url: 'https://a', content: 'one … two', score: 1 },+ { title: 'https://b', url: 'https://b', content: '', score: 0.5 },+ ]);+ });++ it('reads an MCP reply sent as an event stream', async () => {+ seedParallel();+ addKey('parallel', 'no-key');+ mockFetch(() => new Response(`event: message\ndata: ${JSON.stringify(mcpReply(hits))}\n\n`, {+ status: 200,+ headers: { 'content-type': 'text/event-stream' },+ }));+ const out = await runSearch('q');+ expect(out.results.map(r => r.url)).toEqual(['https://a', 'https://b']);+ });++ it('uses the REST API with x-api-key when a real key is stored', async () => {+ seedParallel();+ addKey('parallel', 'real-parallel-key');+ const fn = mockFetch(() => json(hits));+ const out = await runSearch('q', { maxResults: 1 });+ const [url, init] = calls(fn)[0];+ expect(url).toBe('https://api.parallel.ai/v1/search');+ expect((init.headers as Record<string, string>)['x-api-key']).toBe('real-parallel-key');+ expect(bodyOf(calls(fn)[0])).toEqual({ objective: 'q', search_queries: ['q'], mode: 'fast', advanced_settings: { max_results: 1 } });+ expect(out.results).toHaveLength(1);+ });++ it('turns an MCP rate-limit tool error into a retryable 429', async () => {+ seedParallel();+ addKey('parallel', 'no-key');+ mockFetch(() => json({ jsonrpc: '2.0', id: 1, result: { isError: true, content: [{ type: 'text', text: 'Rate limit exceeded for free tier' }] } }));+ await expect(runSearch('q')).rejects.toMatchObject({ status: 429 });+ expect(logRows()).toEqual([expect.objectContaining({ platform: 'parallel', status: 'error' })]);+ });++ it('fails over to the next engine when the MCP call errors', async () => {+ seedParallel();+ addKey('parallel', 'no-key');+ addKey('tavily');+ updateSearchEngine(listSearchEngines().find(e => e.engineId === 'parallel-search')!.id, { priority: 0 });+ mockFetch(url => url.startsWith('https://search.parallel.ai')+ ? json({ jsonrpc: '2.0', id: 1, error: { code: -32603, message: 'internal error' } })+ : json({ results: [{ title: 'T', url: 'https://t', content: 'c' }] }));+ const out = await runSearch('q');+ expect(out.provider).toBe('tavily');+ });+ });+it('tries a custom relay before the catalog engines', async () => {addKey('tavily');addCustomRelay('https://relay.example/v1');diff --git a/server/src/docs/openapi.ts b/server/src/docs/openapi.tsindex 059068ff..cf9e8024 100644--- a/server/src/docs/openapi.ts+++ b/server/src/docs/openapi.ts@@ -35,7 +35,7 @@ export const openapiSpec = {tags: [{ name: 'Chat', description: 'OpenAI-compatible chat and completion endpoints' },{ name: 'Media', description: 'Image generation and text-to-speech' },- { name: 'Search', description: 'Web search over your Tavily, Exa, Firecrawl and Linkup keys' },+ { name: 'Search', description: 'Web search over Parallel (keyless) and your Tavily, Exa, Firecrawl and Linkup keys' },{ name: 'Responses', description: 'OpenAI Responses API (Codex CLI wire format)' },{ name: 'Anthropic', description: 'Anthropic Messages API (Claude Code and the Anthropic SDKs)' },{ name: 'Models', description: 'Model discovery' },@@ -178,7 +178,7 @@ export const openapiSpec = {operationId: 'createSearch',summary: 'Search the web',description:- 'Web search routed over the search engines in the catalog (Tavily, Exa, Firecrawl, Linkup) and any ' ++ 'Web search routed over the search engines in the catalog (Parallel, Tavily, Exa, Firecrawl, Linkup) and any ' +'custom search relay. Omit `engine` (or set `auto`) to fail over across engines that have a key; ' +'rate-limited or out-of-credit keys cool down and the next one is tried.',requestBody: {diff --git a/server/src/lib/key-parser.ts b/server/src/lib/key-parser.tsindex 65f37ffc..e2c20e68 100644--- a/server/src/lib/key-parser.ts+++ b/server/src/lib/key-parser.ts@@ -101,6 +101,7 @@ export const PREFIX_MAP: Record<string, string> = {EXA_: 'exa',FIRECRAWL_: 'firecrawl',LINKUP_: 'linkup',+ PARALLEL_: 'parallel',CLOUDFLARE_: 'cloudflare',ZHIPU_: 'zhipu',OLLAMA_: 'ollama',@@ -242,6 +243,7 @@ export const AUTH_JSON_PROVIDER_MAP: Record<string, string> = {exa: 'exa',firecrawl: 'firecrawl',linkup: 'linkup',+ parallel: 'parallel',};export function detectPlatform(prefix: string): string | null {diff --git a/server/src/lib/search-platforms.ts b/server/src/lib/search-platforms.tsindex 7a54d447..422b7721 100644--- a/server/src/lib/search-platforms.ts+++ b/server/src/lib/search-platforms.ts@@ -3,7 +3,7 @@ import type { SearchPlatform } from '@freellmapi/shared/types.js';// Runtime copy of shared/types.ts SEARCH_PLATFORMS. The server only ever// imports types from @freellmapi/shared (it is not compiled into dist), so the// list lives here too; a test pins the two together.-export const SEARCH_PLATFORMS: readonly SearchPlatform[] = ['tavily', 'exa', 'firecrawl', 'linkup'];+export const SEARCH_PLATFORMS: readonly SearchPlatform[] = ['tavily', 'exa', 'firecrawl', 'linkup', 'parallel'];const SEARCH_PLATFORM_SET = new Set<string>(SEARCH_PLATFORMS);diff --git a/server/src/providers/index.ts b/server/src/providers/index.tsindex a0c43aac..9e7c3791 100644--- a/server/src/providers/index.ts+++ b/server/src/providers/index.ts@@ -7,6 +7,7 @@ import { TavilyProvider } from './tavily.js';import { ExaProvider } from './exa.js';import { FirecrawlProvider } from './firecrawl.js';import { LinkupProvider } from './linkup.js';+import { ParallelProvider } from './parallel.js';import { CloudflareProvider } from './cloudflare.js';import { AIHordeProvider } from './aihorde.js';import { ModelScopeProvider } from './modelscope.js';@@ -213,6 +214,8 @@ register(new TavilyProvider());register(new ExaProvider());register(new FirecrawlProvider());register(new LinkupProvider());+// Keyless: anonymous Search MCP by default, REST API with a real key.+register(new ParallelProvider());// Cloudflare Workers AI - OpenAI-compatible endpoint (key = "account_id:token")register(new CloudflareProvider());diff --git a/server/src/providers/parallel.ts b/server/src/providers/parallel.tsnew file mode 100644index 00000000..65288abc--- /dev/null+++ b/server/src/providers/parallel.ts@@ -0,0 +1,42 @@+import type { Platform } from '@freellmapi/shared/types.js';+import type { KeyValidationResult } from './base.js';+import { SearchOnlyProvider } from './search-only.js';+import { isAnonymousCredential } from '../lib/credential.js';++export const PARALLEL_BASE_URL = 'https://api.parallel.ai/v1';+export const PARALLEL_MCP_URL = 'https://search.parallel.ai/mcp';++// Parallel (parallel.ai): keyless web search. The Search MCP server answers+// anonymous `tools/call web_search` requests with no account, rate-limited per+// caller, so the Keys page stores the `no-key` sentinel and search runs over+// MCP. A real API key (free signup credits) switches to the REST Search API,+// which has published, higher limits.+//+// Validation spends nothing either way: the sentinel is checked with an MCP+// `initialize`, and a real key with an empty POST /v1/search, which a valid key+// answers 422 (no search_queries) and a bad one 401.+export class ParallelProvider extends SearchOnlyProvider {+ readonly platform: Platform = 'parallel';+ readonly name = 'Parallel';+ keyless = true;++ async validateKey(apiKey: string): Promise<KeyValidationResult> {+ if (isAnonymousCredential(apiKey)) {+ return this.probe(PARALLEL_MCP_URL, {+ method: 'POST',+ headers: { 'Content-Type': 'application/json', Accept: 'application/json, text/event-stream' },+ body: JSON.stringify({+ jsonrpc: '2.0',+ id: 1,+ method: 'initialize',+ params: { protocolVersion: '2025-06-18', capabilities: {}, clientInfo: { name: 'freellmapi', version: '1' } },+ }),+ });+ }+ return this.probe(`${PARALLEL_BASE_URL}/search`, {+ method: 'POST',+ headers: { 'x-api-key': apiKey.trim(), 'Content-Type': 'application/json' },+ body: '{}',+ });+ }+}diff --git a/server/src/routes/keys.ts b/server/src/routes/keys.tsindex e5c499aa..4aa42846 100644--- a/server/src/routes/keys.ts+++ b/server/src/routes/keys.ts@@ -56,7 +56,7 @@ const PLATFORMS = ['moondream','freeai','google', 'groq', 'cerebras', 'sail', 'electronhub', 'experiential', 'router9', 'septor', 'clod', 'speechify', 'blaze', 'lucidity', 'airforce', 'dreamprompting', 'waterfall', 'logfare', 'bai', 'radeon', 'nvidia', 'mistral',- 'openrouter', 'github', 'cohere', 'tavily', 'exa', 'firecrawl', 'linkup', 'cloudflare', 'zhipu', 'ollama',+ 'openrouter', 'github', 'cohere', 'tavily', 'exa', 'firecrawl', 'linkup', 'parallel', 'cloudflare', 'zhipu', 'ollama','kilo', 'pollinations', 'llm7', 'huggingface', 'opencode', 'ovh', 'agnes', 'reka', 'siliconflow','routeway', 'bazaarlink', 'ainative', 'aion', 'anyapi', 'requesty', 'navy', 'nara', 'sealion', 'orcarouter', 'unorouter', 'xkiro', 'modelscope','qianfan', 'volcengine', 'longcat', 'xfyun', 'aihorde', 'custom',diff --git a/server/src/routes/mcp.ts b/server/src/routes/mcp.tsindex da70d56b..b2cc5ada 100644--- a/server/src/routes/mcp.ts+++ b/server/src/routes/mcp.ts@@ -494,7 +494,7 @@ const TOOLS: Record<string, McpTool> = {},web_search: {title: 'Search the web',- description: 'Search the web through the search providers configured in FreeLLMAPI (Tavily, Exa, Firecrawl, Linkup, or a custom search endpoint). Returns titles, URLs and short extracts. Spends the search provider\'s free quota, not model tokens.',+ description: 'Search the web through the search providers configured in FreeLLMAPI (Parallel, Tavily, Exa, Firecrawl, Linkup, or a custom search endpoint). Returns titles, URLs and short extracts. Spends the search provider\'s free quota, not model tokens.',inputSchema: {type: 'object',additionalProperties: false,diff --git a/server/src/services/search.ts b/server/src/services/search.tsindex d45a7829..872c7df3 100644--- a/server/src/services/search.ts+++ b/server/src/services/search.ts@@ -8,6 +8,9 @@ import { TAVILY_BASE_URL } from '../providers/tavily.js';import { EXA_BASE_URL } from '../providers/exa.js';import { FIRECRAWL_BASE_URL } from '../providers/firecrawl.js';import { LINKUP_BASE_URL } from '../providers/linkup.js';+import { PARALLEL_BASE_URL, PARALLEL_MCP_URL } from '../providers/parallel.js';+import { isAnonymousCredential } from '../lib/credential.js';+import { randomUUID } from 'node:crypto';import { secondsUntilNextMonth } from './key-budget.js';import { reserveProviderCredential, type ReservedProviderCredential } from './provider-credential.js';import { isOnCooldown, setCooldown } from './ratelimit.js';@@ -188,9 +191,20 @@ async function upstream(url: string, platform: string, init: RequestInit, signalparseRetryAfterMs(res.headers?.get('retry-after') ?? null),);}+ // MCP servers may answer a POST as a one-event stream instead of plain JSON.+ if ((res.headers?.get('content-type') ?? '').includes('text/event-stream')) {+ return lastSseJson(await res.text());+ }return res.json();}+/** The JSON payload of the last `data:` event in an SSE body. */+function lastSseJson(body: string): unknown {+ const data = body.split('\n').filter(l => l.startsWith('data:')).map(l => l.slice(5).trim()).filter(Boolean);+ if (data.length === 0) throw new SearchError('upstream sent an empty event stream', 502);+ return JSON.parse(data[data.length - 1]!);+}+const str = (v: unknown): string => (typeof v === 'string' ? v : '');const clip = (v: string): string => (v.length > CONTENT_CHARS ? `${v.slice(0, CONTENT_CHARS)}…` : v);/** Engines that do not score hits keep their own ranking: 1.0 down to ~0. */@@ -221,6 +235,28 @@ function keepHits(hits: Array<{ title: string; url: string; content: string; sco}));}+// Parallel's anonymous Search MCP asks for a stable conversation id on every+// call (used for its free-tier rate limiting); one per server process.+const PARALLEL_SESSION_ID = `freellmapi-${randomUUID()}`;+const RATE_LIMIT_TEXT = /rate.?limit|too many requests|quota/i;++/** Unwrap a JSON-RPC `tools/call` reply from Parallel's Search MCP into the+ * REST-shaped search response its text content carries. */+function parallelMcpPayload(rpc: unknown): { results?: Array<Record<string, unknown>> } {+ const r = rpc as { error?: { message?: unknown }; result?: { isError?: boolean; content?: Array<{ type?: string; text?: unknown }> } };+ const text = (r?.result?.content ?? []).find(c => c?.type === 'text' && typeof c.text === 'string')?.text as string | undefined;+ const failure = typeof r?.error?.message === 'string' ? r.error.message : (r?.result?.isError ? (text ?? 'tool error') : null);+ if (failure !== null) {+ throw new SearchError(`parallel MCP: ${failure.slice(0, 200)}`, RATE_LIMIT_TEXT.test(failure) ? 429 : 502);+ }+ if (!text) throw new SearchError('parallel MCP returned no text content', 502);+ try {+ return JSON.parse(text) as { results?: Array<Record<string, unknown>> };+ } catch {+ throw new SearchError('parallel MCP returned non-JSON content', 502);+ }+}+/** Tavily's wire shape, shared by Tavily itself and custom search relays. */async function tavilyShaped(url: string, platform: string, cred: ReservedProviderCredential, query: string, opts: SearchOptions, maxResults: number): Promise<AdapterResult> {const body: Record<string, unknown> = { query, max_results: maxResults };@@ -307,6 +343,34 @@ const ADAPTERS: Record<string, Adapter> = {.map(r => ({ title: str(r.name), url: str(r.url), content: str(r.content) }));return { results: keepHits(hits) };},++ // Keyless: the stored `no-key` sentinel goes through the anonymous Search+ // MCP; a real key uses the REST API. Both return the same result shape.+ parallel: async (cred, query, opts, n) => {+ const args = { objective: query, search_queries: [query] };+ const parsed = isAnonymousCredential(cred.key)+ ? parallelMcpPayload(await upstream(PARALLEL_MCP_URL, 'parallel', {+ method: 'POST',+ headers: { 'Content-Type': 'application/json', Accept: 'application/json, text/event-stream' },+ body: JSON.stringify({+ jsonrpc: '2.0',+ id: 1,+ method: 'tools/call',+ params: { name: 'web_search', arguments: { ...args, session_id: PARALLEL_SESSION_ID } },+ }),+ }, opts.signal))+ : await upstream(`${PARALLEL_BASE_URL}/search`, 'parallel', {+ method: 'POST',+ headers: { 'x-api-key': cred.key.trim(), 'Content-Type': 'application/json' },+ body: JSON.stringify({ ...args, mode: 'fast', advanced_settings: { max_results: n } }),+ }, opts.signal) as { results?: Array<Record<string, unknown>> };+ const hits = (Array.isArray(parsed?.results) ? parsed.results : []).slice(0, n).map(r => ({+ title: str(r.title) || str(r.url),+ url: str(r.url),+ content: Array.isArray(r.excerpts) ? r.excerpts.filter(e => typeof e === 'string').join(' … ') : '',+ }));+ return { results: keepHits(hits) };+ },};/** Platforms with a search adapter. catalog-sync gates searchEngines rows on@@ -447,7 +511,7 @@ export async function runSearch(query: string, opts: SearchOptions = {}): Promis);}throw new SearchError(- 'No search key configured. Add a Tavily, Exa, Firecrawl or Linkup key on the Keys page.',+ 'No search key configured. Enable Parallel (no key needed) or add a Tavily, Exa, Firecrawl or Linkup key on the Keys page.',503,'no_search_keys',);diff --git a/shared/types.ts b/shared/types.tsindex 26609fec..f2152049 100644--- a/shared/types.ts+++ b/shared/types.ts@@ -136,6 +136,7 @@ export type Platform =| 'exa'| 'firecrawl'| 'linkup'+ | 'parallel'| 'cloudflare'| 'zhipu'| 'ollama'@@ -264,7 +265,7 @@ export type Platform =* web_search tools), never chat. Search engine rows arrive through the* catalog's `searchEngines` registry. The server keeps its own runtime copy in* server/src/lib/search-platforms.ts (shared is type-only on the server). */-export const SEARCH_PLATFORMS = ['tavily', 'exa', 'firecrawl', 'linkup'] as const;+export const SEARCH_PLATFORMS = ['tavily', 'exa', 'firecrawl', 'linkup', 'parallel'] as const;export type SearchPlatform = (typeof SEARCH_PLATFORMS)[number];export function isSearchPlatform(platform: string): platform is SearchPlatform {