Add authHeader option and fix print mode error handling

- Add 'authHeader' boolean option to models.json provider config
  When true, adds 'Authorization: Bearer <apiKey>' to model headers
  Useful for providers requiring explicit auth headers (fixes #81)

- Fix print mode (-p) silently failing on errors
  Now outputs error message to stderr and exits with code 1
  when assistant message has stopReason of error/aborted
This commit is contained in:
Mario Zechner 2025-12-05 11:31:14 +01:00
parent 398591fdb0
commit 51195bc9fc
3 changed files with 24 additions and 2 deletions

View file

@ -46,6 +46,7 @@ const ProviderConfigSchema = Type.Object({
]),
),
headers: Type.Optional(Type.Record(Type.String(), Type.String())),
authHeader: Type.Optional(Type.Boolean()),
models: Type.Array(ModelDefinitionSchema),
});
@ -177,9 +178,17 @@ function parseModels(config: ModelsConfig): Model<Api>[] {
}
// Merge headers: provider headers are base, model headers override
const headers =
let headers =
providerConfig.headers || modelDef.headers ? { ...providerConfig.headers, ...modelDef.headers } : undefined;
// If authHeader is true, add Authorization header with resolved API key
if (providerConfig.authHeader) {
const resolvedKey = resolveApiKey(providerConfig.apiKey);
if (resolvedKey) {
headers = { ...headers, Authorization: `Bearer ${resolvedKey}` };
}
}
models.push({
id: modelDef.id,
name: modelDef.name,