Skip to content

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(providers): add Auray and preserve native Gemini TTS WAV (#1518)

Tashfeen5a3abac8b428
diff --git a/client/src/components/keys/shared.tsx b/client/src/components/keys/shared.tsx
index 4dd659a9..001fcac8 100644
--- a/client/src/components/keys/shared.tsx
+++ b/client/src/components/keys/shared.tsx
@@ -29,6 +29,7 @@ export function GetKeyLink({ url }: { url: string }) {
export const PLATFORMS: { value: Platform; label: string; url: string; keyless?: boolean }[] = [
{ value: 'aclide', label: 'ACLIDE (shared monthly credits)', url: 'https://aclide.com/en/dashboard/api-keys' },
{ value: 'speka', label: 'Speka ($1 shared monthly credits)', url: 'https://speka.me/dashboard/keys' },
+ { value: 'auray', label: 'Auray (50 shared monthly credits)', url: 'https://app.auray.ai' },
{ value: 'typhoon', label: 'Typhoon (free research API)', url: 'https://playground.opentyphoon.ai' },
{ value: 'plugsky', label: 'Plugsky (free chat aliases)', url: 'https://plugsky.com/dashboard' },
{ value: 'inferbase', label: 'Inferbase (shared monthly and daily allowance)', url: 'https://inferbase.ai' },
diff --git a/client/src/lib/routing.ts b/client/src/lib/routing.ts
index 21109d7c..cb487112 100644
--- a/client/src/lib/routing.ts
+++ b/client/src/lib/routing.ts
@@ -405,6 +405,7 @@ export const platformColors: Record<string, string> = {
sail: '#0ea5e9',
aclide: '#6366f1',
speka: '#0d9488',
+ auray: '#635bff',
typhoon: '#e11d48',
plugsky: '#0284c7',
inferbase: '#2563eb',
diff --git a/server/src/__tests__/providers/auray.test.ts b/server/src/__tests__/providers/auray.test.ts
new file mode 100644
index 00000000..64bed24c
--- /dev/null
+++ b/server/src/__tests__/providers/auray.test.ts
@@ -0,0 +1,91 @@
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { AurayProvider, AURAY_BASE_URL } from '../../providers/auray.js';
+import { getProvider } from '../../providers/index.js';
+import { AUTH_JSON_PROVIDER_MAP, parseKeysFromFile } from '../../lib/key-parser.js';
+import { supportedParametersFor } from '../../lib/sampling-params.js';
+
+const model = 'glm-5-3-flash';
+const json = (body: unknown, status = 200, headers = {}) => new Response(JSON.stringify(body), { status, headers });
+const completion = { id: 'test', object: 'chat.completion', created: 1, model,
+ choices: [{ index: 0, message: { role: 'assistant', content: 'OK' }, finish_reason: 'stop' }],
+ usage: { prompt_tokens: 3, completion_tokens: 1, total_tokens: 4 } };
+const frame = { id: 'test', object: 'chat.completion.chunk', created: 1, model,
+ choices: [{ index: 0, delta: { role: 'assistant', content: 'OK' }, finish_reason: null }] };
+const sse = (frames: unknown[]) => new Response(': keepalive\n\n' + frames.map(x => `data: ${JSON.stringify(x)}\n\n`).join('') + 'data: [DONE]\n\n', { headers: { 'content-type': 'text/event-stream' } });
+
+describe('Auray catalog-only provider', () => {
+ afterEach(() => vi.restoreAllMocks());
+
+ it('registers the provider and explicit key import aliases', () => {
+ expect(getProvider('auray')).toBeInstanceOf(AurayProvider);
+ expect(getProvider('auray')!.keyless).toBe(false);
+ expect(parseKeysFromFile('AURAY_API_KEY=auray_sk_test_only', 'keys.env').keys[0].platform).toBe('auray');
+ expect(AUTH_JSON_PROVIDER_MAP.auray).toBe('auray');
+ });
+
+ it('does not advertise sampling controls that the provider ignores', () => {
+ expect(supportedParametersFor('auray')).toEqual(['max_tokens', 'max_completion_tokens', 'stream', 'response_format', 'reasoning_effort']);
+ expect(supportedParametersFor('auray', { tools: true })).toEqual(['max_tokens', 'max_completion_tokens', 'stream', 'response_format', 'reasoning_effort', 'tools', 'tool_choice']);
+ });
+
+ it.each([0, 50])('validates an authenticated account with %s credits without inference', async balance => {
+ const fetch = vi.spyOn(global, 'fetch').mockResolvedValue(json({ plan: 'free', credits: { balance } }));
+ expect(await new AurayProvider().validateKey('test-key')).toBe(true);
+ expect(fetch.mock.calls[0][0]).toBe('https://api.auray.ai/v1/me');
+ expect(fetch.mock.calls[0][1]?.method).toBe('GET');
+ expect(new Headers(fetch.mock.calls[0][1]?.headers).get('authorization')).toBe('Bearer test-key');
+ expect(fetch).toHaveBeenCalledTimes(1);
+ });
+
+ it.each([401, 403])('rejects authentication failures %s', async status => {
+ vi.spyOn(global, 'fetch').mockResolvedValue(json({ error: { message: 'Invalid key' } }, status));
+ await expect(new AurayProvider().validateKey('bad-key')).resolves.toMatchObject({ valid: false });
+ });
+
+ it.each([402, 429, 503])('keeps HTTP %s inconclusive and preserves Retry-After', async status => {
+ vi.spyOn(global, 'fetch').mockResolvedValue(json({}, status, { 'Retry-After': '45' }));
+ await expect(new AurayProvider().validateKey('test-key')).rejects.toMatchObject({ status, retryAfterMs: 45_000 });
+ });
+
+ it.each([{}, null, { plan: 'free', credits: { balance: '50' } }])('rejects malformed account responses', async body => {
+ vi.spyOn(global, 'fetch').mockResolvedValue(json(body));
+ await expect(new AurayProvider().validateKey('test-key')).rejects.toMatchObject({ status: 502 });
+ });
+
+ it('uses the compatibility endpoint, preserving options and usage', async () => {
+ const fetch = vi.spyOn(global, 'fetch').mockResolvedValue(json(completion));
+ const out = await new AurayProvider().chatCompletion('test-key', [{ role: 'user', content: 'Hi' }], model,
+ { max_tokens: 256, reasoning_effort: 'minimal', response_format: { type: 'json_object' } });
+ expect(fetch.mock.calls[0][0]).toBe(`${AURAY_BASE_URL}/chat/completions`);
+ expect(new Headers(fetch.mock.calls[0][1]?.headers).get('authorization')).toBe('Bearer test-key');
+ expect(JSON.parse(String(fetch.mock.calls[0][1]?.body))).toMatchObject({ model, max_tokens: 256, reasoning_effort: 'minimal', response_format: { type: 'json_object' } });
+ expect(out.usage?.total_tokens).toBe(4);
+ expect(out._routed_via).toEqual({ platform: 'auray', model });
+ });
+
+ it.each([{ ...completion, model: 'substitute' }, { ...completion, model: undefined }, { ...completion, choices: [] }, { error: { code: 'vendor_disabled' } }])('fails closed on mismatched/malformed HTTP 200', async body => {
+ vi.spyOn(global, 'fetch').mockResolvedValue(json(body));
+ await expect(new AurayProvider().chatCompletion('test-key', [], model)).rejects.toMatchObject({ status: 502 });
+ });
+
+ it('preserves HTTP rate-limit hints without retrying a paid request', async () => {
+ const fetch = vi.spyOn(global, 'fetch').mockResolvedValue(json({ error: { message: 'Rate limited' } }, 429, { 'Retry-After': '45' }));
+ await expect(new AurayProvider().chatCompletion('test-key', [], model)).rejects.toMatchObject({ status: 429, retryAfterMs: 45_000 });
+ expect(fetch).toHaveBeenCalledTimes(1);
+ });
+
+ it('streams text, tools, reasoning and usage-only events', async () => {
+ const tools = [{ index: 0, id: 'call_au_1', type: 'function', function: { name: 'test', arguments: '{}' } }];
+ vi.spyOn(global, 'fetch').mockResolvedValue(sse([frame, { ...frame, choices: [{ index: 0, delta: { reasoning_content: 'reason', tool_calls: tools }, finish_reason: 'tool_calls' }] }, { ...frame, choices: [], usage: completion.usage }]));
+ const chunks = [];
+ for await (const c of new AurayProvider().streamChatCompletion('test-key', [], model)) chunks.push(c);
+ expect(chunks[0].choices[0].delta.content).toBe('OK');
+ expect(chunks[1].choices[0].delta.tool_calls?.[0].id).toBe('call_au_1');
+ expect(chunks.at(-1)?.usage?.total_tokens).toBe(4);
+ });
+
+ it.each([[], [{ ...frame, model: 'other' }], [{ ...frame, choices: undefined }], [frame, { error: { code: 'vendor_disabled' } }]].map(frames => ({ frames })))('rejects empty, substituted or deferred-error streams', async ({ frames }) => {
+ vi.spyOn(global, 'fetch').mockResolvedValue(sse(frames));
+ await expect((async () => { for await (const _chunk of new AurayProvider().streamChatCompletion('test-key', [], model)) { /* drain */ } })()).rejects.toMatchObject({ status: 502 });
+ });
+});
diff --git a/server/src/__tests__/services/auray-embeddings.test.ts b/server/src/__tests__/services/auray-embeddings.test.ts
new file mode 100644
index 00000000..e8724f87
--- /dev/null
+++ b/server/src/__tests__/services/auray-embeddings.test.ts
@@ -0,0 +1,61 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { getDb, initDb } from '../../db/index.js';
+import { encrypt } from '../../lib/crypto.js';
+import { EMBEDDING_PLATFORMS, runEmbeddings } from '../../services/embeddings.js';
+import { applyCatalog } from '../../services/catalog-sync.js';
+
+const model = 'qwen3-embedding-8b';
+const json = (body: unknown) => new Response(JSON.stringify(body));
+function seed() {
+ const db = getDb(), secret = encrypt('auray-test-key');
+ db.prepare("INSERT INTO api_keys (platform,label,encrypted_key,iv,auth_tag,status,enabled) VALUES ('auray','test',?,?,?,'healthy',1)").run(secret.encrypted, secret.iv, secret.authTag);
+ const result = applyCatalog(db, { version: '2099.01.01', generatedAt: new Date().toISOString(), tier: 'live', models: [], quirks: [],
+ embeddings: [{ platform: 'auray', modelId: model, family: 'auray-test', displayName: model, dimensions: 4096, maxInputTokens: 40960, priority: 1, enabled: true, quotaLabel: '50 monthly credits shared' }] });
+ expect(result.skippedUnknownPlatform).toBe(0);
+}
+
+describe('Auray catalog-managed embeddings', () => {
+ beforeEach(() => { process.env.ENCRYPTION_KEY = '0'.repeat(64); initDb(':memory:'); });
+ afterEach(() => { vi.restoreAllMocks(); getDb().close(); });
+
+ it('routes ordered fixed-width vectors with a cold-start timeout and usage', async () => {
+ seed();
+ const timeout = vi.spyOn(AbortSignal, 'timeout');
+ const fetch = vi.spyOn(global, 'fetch').mockResolvedValue(json({ model, data: [{ index: 1, embedding: Array(4096).fill(0.2) }, { index: 0, embedding: Array(4096).fill(0.1) }], usage: { prompt_tokens: 6 } }));
+ const result = await runEmbeddings('auray-test', ['first', 'second']);
+ expect(EMBEDDING_PLATFORMS.has('auray')).toBe(true);
+ expect(timeout).toHaveBeenCalledWith(180_000);
+ expect(fetch.mock.calls[0][0]).toBe('https://api.auray.ai/openai/v1/embeddings');
+ expect(new Headers(fetch.mock.calls[0][1]?.headers).get('authorization')).toBe('Bearer auray-test-key');
+ expect(JSON.parse(String(fetch.mock.calls[0][1]?.body))).toEqual({ model, input: ['first', 'second'] });
+ expect(result).toMatchObject({ platform: 'auray', modelId: model, dimensions: 4096, inputTokens: 6 });
+ expect(result.vectors.map(v => v[0])).toEqual([0.1, 0.2]);
+ });
+
+ it.each([
+ { model: 'other', data: [{ index: 0, embedding: Array(4096).fill(0.1) }] },
+ { model, data: [] },
+ { model, data: [{ index: 0, embedding: [0.1] }] },
+ { model, data: [{ index: 0, embedding: Array(4096).fill(null) }] },
+ { model, data: [{ index: 1, embedding: Array(4096).fill(0.1) }] },
+ { error: { code: 'insufficient_credits' } },
+ ])('rejects invalid model identity, vector dimensions or values', async body => {
+ seed(); vi.spyOn(global, 'fetch').mockResolvedValue(json(body));
+ await expect(runEmbeddings('auray-test', ['hello'])).rejects.toMatchObject({ status: 502 });
+ });
+
+ it('does not send an unsupported dimension override', async () => {
+ seed(); const fetch = vi.spyOn(global, 'fetch');
+ await expect(runEmbeddings('auray-test', ['hello'], 1024)).rejects.toThrow('dimension override');
+ expect(fetch).not.toHaveBeenCalled();
+ });
+
+ it('preserves rate-limit retry hints', async () => {
+ seed(); vi.spyOn(global, 'fetch').mockResolvedValue(new Response('rate limited', { status: 429, headers: { 'Retry-After': '45' } }));
+ await expect(runEmbeddings('auray-test', ['hello'])).rejects.toMatchObject({ status: 429, retryAfterMs: 45_000 });
+ });
+
+ it('does not seed new models before the signed catalog arrives', () => {
+ for (const table of ['models', 'embedding_models']) expect(getDb().prepare(`SELECT COUNT(*) AS n FROM ${table} WHERE platform='auray'`).get()).toEqual({ n: 0 });
+ });
+});
diff --git a/server/src/__tests__/services/media.test.ts b/server/src/__tests__/services/media.test.ts
index d4a947b0..8bb1e560 100644
--- a/server/src/__tests__/services/media.test.ts
+++ b/server/src/__tests__/services/media.test.ts
@@ -648,6 +648,27 @@ describe('media service', () => {
expect(body.generationConfig.speechConfig.voiceConfig.prebuiltVoiceConfig.voiceName).toBe('Schedar');
});
+ it.each(['gemini-3.8-flash-tts', 'gemini-3.8-flash-lite-tts'])('Gemini TTS: passes through existing WAV bytes for %s', async model => {
+ addMedia('google', model, 'audio');
+ addKey('google');
+ const wav = Buffer.alloc(48);
+ wav.write('RIFF', 0); wav.writeUInt32LE(40, 4); wav.write('WAVE', 8);
+ wav.write('fmt ', 12); wav.writeUInt32LE(16, 16); wav.writeUInt16LE(1, 20);
+ wav.writeUInt16LE(1, 22); wav.writeUInt32LE(24000, 24); wav.writeUInt32LE(48000, 28);
+ wav.writeUInt16LE(2, 32); wav.writeUInt16LE(16, 34); wav.write('data', 36); wav.writeUInt32LE(4, 40);
+ globalThis.fetch = vi.fn(async () => jsonResponse({ candidates: [{ content: { parts: [{ inlineData: { mimeType: 'audio/wav', data: wav.toString('base64') } }] } }] }));
+ const result = await runSpeech(model, { input: 'hello' });
+ expect(result.audio).toEqual(wav);
+ expect(result.contentType).toBe('audio/wav');
+ });
+
+ it('Gemini TTS: rejects an invalid declared WAV rather than wrapping it as PCM', async () => {
+ addMedia('google', 'gemini-3.8-flash-tts', 'audio');
+ addKey('google');
+ globalThis.fetch = vi.fn(async () => jsonResponse({ candidates: [{ content: { parts: [{ inlineData: { mimeType: 'audio/wav', data: Buffer.from('not audio').toString('base64') } }] } }] }));
+ await expect(runSpeech('gemini-3.8-flash-tts', { input: 'hello' })).rejects.toThrow('malformed WAV');
+ });
+
it('Gemini TTS: canonicalizes native voices and defaults unknown names', async () => {
addMedia('google', 'gemini-2.5-flash-preview-tts', 'audio');
addKey('google');
diff --git a/server/src/lib/key-parser.ts b/server/src/lib/key-parser.ts
index 57999d61..65f37ffc 100644
--- a/server/src/lib/key-parser.ts
+++ b/server/src/lib/key-parser.ts
@@ -46,6 +46,7 @@ export interface ParseResult {
export const PREFIX_MAP: Record<string, string> = {
ACLIDE_: 'aclide',
SPEKA_: 'speka',
+ AURAY_: 'auray',
TYPHOON_: 'typhoon',
PLUGSKY_: 'plugsky',
INFERBASE_: 'inferbase',
@@ -156,6 +157,7 @@ export const AUTH_JSON_PROVIDER_MAP: Record<string, string> = {
sail: 'sail',
aclide: 'aclide',
speka: 'speka',
+ auray: 'auray',
typhoon: 'typhoon',
plugsky: 'plugsky',
inferbase: 'inferbase',
diff --git a/server/src/lib/sampling-params.ts b/server/src/lib/sampling-params.ts
index a68d0f6f..55b0d0d8 100644
--- a/server/src/lib/sampling-params.ts
+++ b/server/src/lib/sampling-params.ts
@@ -448,6 +448,12 @@ export function platformDropsResponseFormat(platform: string): boolean {
export function supportedParametersFor(platform: string, caps: { tools?: boolean } = {}): string[] {
// Unlike the generic base set, Moondream has neither stop nor tools.
if (platform === 'moondream') return ['temperature', 'top_p', 'max_tokens', 'max_completion_tokens', 'stream', 'reasoning_effort'];
+ // Auray accepts sampling knobs for client compatibility but does not apply
+ // them. Advertise only controls its built-in models actually honor.
+ if (platform === 'auray') return [
+ 'max_tokens', 'max_completion_tokens', 'stream', 'response_format', 'reasoning_effort',
+ ...(caps.tools ? ['tools', 'tool_choice'] : []),
+ ];
const policy = PLATFORM_PARAM_POLICIES[platform as Platform];
const dropped = new Set<string>(policy?.drop ?? []);
const params = [
diff --git a/server/src/providers/auray.ts b/server/src/providers/auray.ts
new file mode 100644
index 00000000..5cc0906c
--- /dev/null
+++ b/server/src/providers/auray.ts
@@ -0,0 +1,68 @@
+import type { ChatCompletionChunk, ChatCompletionResponse, ChatMessage } from '@freellmapi/shared/types.js';
+import { parseStatedRetryMs, providerHttpError, type CompletionOptions, type KeyValidationResult } from './base.js';
+import { OpenAICompatProvider } from './openai-compat.js';
+import type { QuotaObservationContext } from '../services/provider-quota.js';
+
+export const AURAY_BASE_URL = 'https://api.auray.ai/openai/v1';
+
+function checkResponse(value: { model?: string; error?: unknown }, requested: string): void {
+ // Deferred failures can arrive under HTTP 200 or after valid SSE chunks.
+ // Never expose them (or an auto-routed substitute) as a successful answer.
+ if (value.error) {
+ const error = value.error as { code?: string; type?: string };
+ const rateLimited = error.code === 'rate_limited' || error.type === 'insufficient_quota';
+ throw Object.assign(new Error('Auray returned an upstream completion error'), {
+ status: rateLimited ? 429 : 502,
+ retryAfterMs: parseStatedRetryMs(value),
+ });
+ }
+ if (value.model !== requested) {
+ throw Object.assign(new Error('Auray returned a different or missing model identity'), { status: 502 });
+ }
+}
+
+/** Free credits renew monthly and are shared across chat and embeddings.
+ * Only the signed catalog decides which models qualify; no bundled seeds.
+ * https://www.auray.ai/docs/clients/openai */
+export class AurayProvider extends OpenAICompatProvider {
+ constructor() {
+ super({ platform: 'auray', name: 'Auray', baseUrl: AURAY_BASE_URL,
+ validateUrl: 'https://api.auray.ai/v1/me', timeoutMs: 180_000 });
+ }
+
+ protected override async validationResult(response: Response): Promise<KeyValidationResult> {
+ if ([401, 403].includes(response.status)) return super.validationResult(response);
+ if (!response.ok) throw providerHttpError(response, 'Auray key validation is temporarily inconclusive');
+ const body = await response.json().catch(() => null) as { plan?: unknown; credits?: { balance?: unknown } } | null;
+ if (typeof body?.plan !== 'string' || typeof body.credits?.balance !== 'number' || !Number.isFinite(body.credits.balance)) {
+ throw Object.assign(new Error('Auray returned an invalid account response'), { status: 502 });
+ }
+ // An exhausted free wallet is still an authenticated key. /models is a
+ // roster, not an authentication probe; /me never generates paid tokens.
+ return true;
+ }
+
+ override async chatCompletion(apiKey: string, messages: ChatMessage[], modelId: string,
+ options?: CompletionOptions, quotaContext?: QuotaObservationContext): Promise<ChatCompletionResponse> {
+ const response = await super.chatCompletion(apiKey, messages, modelId, options, quotaContext);
+ checkResponse(response, modelId);
+ if (!Array.isArray(response.choices) || response.choices.length === 0 || response.choices.some(c => !c.message)) {
+ throw Object.assign(new Error('Auray returned a malformed completion'), { status: 502 });
+ }
+ return response;
+ }
+
+ override async *streamChatCompletion(apiKey: string, messages: ChatMessage[], modelId: string,
+ options?: CompletionOptions, quotaContext?: QuotaObservationContext): AsyncGenerator<ChatCompletionChunk> {
+ let identified = false;
+ for await (const chunk of super.streamChatCompletion(apiKey, messages, modelId, options, quotaContext)) {
+ checkResponse(chunk, modelId);
+ if (!Array.isArray(chunk.choices) || chunk.choices.some(c => !c.delta)) {
+ throw Object.assign(new Error('Auray returned a malformed stream event'), { status: 502 });
+ }
+ identified = true;
+ yield chunk;
+ }
+ if (!identified) throw Object.assign(new Error('Auray returned an empty stream'), { status: 502 });
+ }
+}
diff --git a/server/src/providers/index.ts b/server/src/providers/index.ts
index deb518f8..a0c43aac 100644
--- a/server/src/providers/index.ts
+++ b/server/src/providers/index.ts
@@ -36,6 +36,7 @@ import { AirforceProvider } from './airforce.js';
import { DreamPromptingProvider } from './dreamprompting.js';
import { WaterfallProvider } from './waterfall.js';
import { LogfareProvider } from './logfare.js';
+import { AurayProvider } from './auray.js';
const providers = new Map<Platform, BaseProvider>();
@@ -79,6 +80,7 @@ register(new LlmtrProvider());
register(new GizmoProvider());
register(new BlockRunProvider());
register(new MoondreamProvider());
+register(new AurayProvider());
// Free-plan grants are shared wallets, not free credits per model. Eligibility
// and tested model rows belong in Oracle, never in bundled DB migrations.
diff --git a/server/src/routes/keys.ts b/server/src/routes/keys.ts
index 1f6ddb42..e5c499aa 100644
--- a/server/src/routes/keys.ts
+++ b/server/src/routes/keys.ts
@@ -45,6 +45,7 @@ export const keysRouter = Router();
const PLATFORMS = [
'aclide',
'speka',
+ 'auray',
'typhoon',
'plugsky',
'inferbase',
diff --git a/server/src/services/embeddings.ts b/server/src/services/embeddings.ts
index 8e75fde8..3790d84a 100644
--- a/server/src/services/embeddings.ts
+++ b/server/src/services/embeddings.ts
@@ -20,6 +20,7 @@ import type { Db } from '../db/types.js';
import { SPEKA_BASE_URL } from '../providers/speka.js';
import { ELECTRONHUB_BASE_URL } from '../providers/electronhub.js';
import { INFERBASE_BASE_URL } from '../providers/inferbase.js';
+import { AURAY_BASE_URL } from '../providers/auray.js';
export interface EmbeddingModelRow {
id: number;
@@ -119,6 +120,7 @@ export const EMBEDDING_PLATFORMS = new Set([
'speka',
'electronhub',
'inferbase',
+ 'auray',
]);
interface ProviderCallResult {
@@ -135,6 +137,7 @@ async function openAiStyleEmbed(
extra: Record<string, unknown> = {},
dimensions?: number,
expectedDimensions?: number,
+ timeoutMs = FETCH_TIMEOUT_MS,
): Promise<ProviderCallResult> {
const body: Record<string, unknown> = { model: modelId, input: inputs, ...extra };
// Some providers (NVIDIA NeMo NIM, Google Gemini Embedding, OpenAI v3) support
@@ -150,8 +153,8 @@ async function openAiStyleEmbed(
// header instead of sending `Bearer no-key` (#1331).
headers: { 'Content-Type': 'application/json', ...bearerAuthHeader(key) },
body: JSON.stringify(body),
- signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
- }, platform, 'embedding', FETCH_TIMEOUT_MS);
+ signal: AbortSignal.timeout(timeoutMs),
+ }, platform, 'embedding', timeoutMs);
if (!r.ok) {
throw await upstreamEmbeddingsError(r);
}
@@ -161,7 +164,7 @@ async function openAiStyleEmbed(
usage?: { prompt_tokens?: number; total_tokens?: number };
};
const data = [...(j.data ?? [])].sort((a, b) => (a.index ?? 0) - (b.index ?? 0));
- if ((platform === 'electronhub' || platform === 'inferbase') && (
+ if (['electronhub', 'inferbase', 'auray'].includes(platform) && (
j.model !== modelId || data.length !== inputs.length ||
data.some((d, i) => d.index !== i || !Array.isArray(d.embedding) ||
d.embedding.length !== (dimensions ?? expectedDimensions) ||
@@ -169,7 +172,7 @@ async function openAiStyleEmbed(
)) {
// A successful HTTP response is not enough: wrong model/dimension or
// malformed vectors would corrupt the caller's embedding family.
- const provider = platform === 'electronhub' ? 'ElectronHub' : 'Inferbase';
+ const provider = platform === 'electronhub' ? 'ElectronHub' : platform === 'auray' ? 'Auray' : 'Inferbase';
throw new EmbeddingsError(`${provider} returned mismatched or malformed embeddings`, 502);
}
return {
@@ -288,6 +291,13 @@ async function callProvider(row: EmbeddingModelRow, credential: ProviderCredenti
return openAiStyleEmbed(`${ELECTRONHUB_BASE_URL}/embeddings`, row.platform, key, row.model_id, inputs, { encoding_format: 'float' }, dimensions, row.dimensions);
case 'inferbase':
return openAiStyleEmbed(`${INFERBASE_BASE_URL}/embeddings`, row.platform, key, row.model_id, inputs, { encoding_format: 'float' }, dimensions, row.dimensions);
+ case 'auray':
+ // Auray documents fixed-width vectors, not Matryoshka truncation. A cold
+ // request can take longer than the generic 30-second embedding deadline.
+ if (dimensions !== undefined && dimensions !== row.dimensions) {
+ throw new EmbeddingsError('Auray does not support an embedding dimension override', 400);
+ }
+ return openAiStyleEmbed(`${AURAY_BASE_URL}/embeddings`, row.platform, key, row.model_id, inputs, {}, undefined, row.dimensions, 180_000);
case 'cloudflare': {
// Key is stored as "account_id:token".
const sep = key.indexOf(':');
diff --git a/server/src/services/media.ts b/server/src/services/media.ts
index 93bc8c22..43374557 100644
--- a/server/src/services/media.ts
+++ b/server/src/services/media.ts
@@ -756,8 +756,8 @@ async function callSpeechProvider(
return { audio: Buffer.from(b64, 'base64'), contentType: contentTypeFor(p.format ?? 'mp3') };
}
case 'google': {
- // Gemini TTS via generateContent (AUDIO modality) returns base64 PCM
- // (L16, mono, ~24kHz); wrap it in a WAV header so clients can play it.
+ // Older Gemini TTS returns PCM; newer models return an entire WAV file.
+ // Preserve WAV bytes instead of wrapping the container a second time.
const r = await mediaFetch(
`https://generativelanguage.googleapis.com/v1beta/models/${row.model_id}:generateContent`,
'google',
@@ -780,8 +780,14 @@ async function callSpeechProvider(
const part = j.candidates?.[0]?.content?.parts?.find(pt => pt.inlineData?.data);
const b64 = part?.inlineData?.data;
if (!b64) throw new MediaError('gemini returned no audio', 502);
+ const audio = Buffer.from(b64, 'base64');
+ const isWav = audio.length >= 44 && audio.subarray(0, 4).toString() === 'RIFF' && audio.subarray(8, 12).toString() === 'WAVE';
+ if (isWav) return { audio, contentType: 'audio/wav' };
+ if (/^audio\/(?:x-)?wav(?:;|$)/i.test(part?.inlineData?.mimeType ?? '')) {
+ throw new MediaError('gemini returned malformed WAV audio', 502);
+ }
const rate = parseRate(part?.inlineData?.mimeType) ?? 24000;
- return { audio: wrapPcmAsWav(Buffer.from(b64, 'base64'), rate), contentType: 'audio/wav' };
+ return { audio: wrapPcmAsWav(audio, rate), contentType: 'audio/wav' };
}
default:
throw new MediaError(`no speech adapter for platform '${row.platform}'`, 500);
diff --git a/shared/types.ts b/shared/types.ts
index ba99d856..26609fec 100644
--- a/shared/types.ts
+++ b/shared/types.ts
@@ -72,6 +72,8 @@ export type Platform =
| 'aclide'
// OpenAI-compatible chat and embeddings; one shared $1 monthly allowance.
| 'speka'
+ // Built-in chat and embeddings share free monthly credits; catalog only.
+ | 'auray'
// Ongoing free research API for chat and speech recognition; catalog only.
| 'typhoon'
// Permanent free chat aliases, shared fair-use quota; signed catalog only.