diff --git a/packages/config-yaml/src/validation.ts b/packages/config-yaml/src/validation.ts index 874eb3ad89..b6378f12e8 100644 --- a/packages/config-yaml/src/validation.ts +++ b/packages/config-yaml/src/validation.ts @@ -12,6 +12,10 @@ export interface ConfigResult { configLoadInterrupted: boolean; } +function containsUnicode(str: string): boolean { + return /[^\x00-\x7F]/.test(str); +} + export function validateConfigYaml( config: ConfigYaml, ): ConfigValidationError[] { @@ -32,6 +36,25 @@ export function validateConfigYaml( if ("uses" in model) { return; } + + // request headers to the llm api should not contain unicode characters + if (model.apiKey && containsUnicode(model.apiKey)) { + errors.push({ + fatal: true, + message: `Model "${model.name}" has an API key containing unicode characters. API keys should only contain ASCII characters.`, + }); + } + + if (model.requestOptions?.headers) { + for (const [key, value] of Object.entries(model.requestOptions.headers)) { + if (containsUnicode(key) || containsUnicode(value)) { + errors.push({ + fatal: true, + message: `Model "${model.name}" has a request header "${key}" containing unicode characters. Request headers should only contain ASCII characters.`, + }); + } + } + } // Max tokens not too close to context length if ( model.defaultCompletionOptions?.contextLength &&