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
fix(keys): drop an opening quote whose closing quote was lost in an imported .env (#1660)
tashdroid7ac118b36e91
diff --git a/server/src/__tests__/lib/key-parser.test.ts b/server/src/__tests__/lib/key-parser.test.tsindex 097a99cd..0327ea68 100644--- a/server/src/__tests__/lib/key-parser.test.ts+++ b/server/src/__tests__/lib/key-parser.test.ts@@ -45,6 +45,26 @@ describe('key parser', () => {]);});+ it('drops an opening quote whose closing quote was lost', () => {+ // Editor auto-quoting or a truncated paste yields `KEY="sk-abc` — the+ // credential must not import with the `"` glued to its front.+ expect(parseDotEnv('OPENAI_API_KEY="sk-abc123')).toEqual([+ { key: 'OPENAI_API_KEY', value: 'sk-abc123' },+ ]);+ expect(parseDotEnv("GROQ_API_KEY='gsk-abc123")).toEqual([+ { key: 'GROQ_API_KEY', value: 'gsk-abc123' },+ ]);+ // ...and the same line with a trailing inline comment.+ expect(parseDotEnv('OPENAI_API_KEY="sk-abc123 # primary')).toEqual([+ { key: 'OPENAI_API_KEY', value: 'sk-abc123' },+ ]);+ // The end-to-end import path: the value feeds the router as-is.+ const result = parseKeysFromFile('GROQ_API_KEY="gsk_te...7890', '.env');+ expect(result.keys).toEqual([+ expect.objectContaining({ rawKey: 'GROQ_API_KEY=gsk_te...7890', platform: 'groq' }),+ ]);+ });+it('parses flat JSON string values', () => {expect(parseJson(JSON.stringify({ MISTRAL_API_KEY: 'mist-test', PORT: 3001 }))).toEqual([{ key: 'MISTRAL_API_KEY', value: 'mist-test' },diff --git a/server/src/lib/key-parser.ts b/server/src/lib/key-parser.tsindex 03f8f00c..cec6843f 100644--- a/server/src/lib/key-parser.ts+++ b/server/src/lib/key-parser.ts@@ -292,6 +292,12 @@ export function parseDotEnv(content: string): Array<{ key: string; value: stringconst commentIndex = value.indexOf(' #');if (commentIndex !== -1) value = value.slice(0, commentIndex);value = value.trimEnd();+ // A dropped closing quote (`KEY="sk-abc`, typically from editor auto-+ // quoting or a truncated paste) left the `"` glued to the credential,+ // and every request with it failed upstream 401 with a message that+ // never mentions the stray quote. No API key starts with a quote+ // character, so dropping the opener is always safe.+ if (quote) value = value.slice(1);}result.set(key, value);