Skip to content

Commit c678a20

Browse files
committed
fix(agents): preserve inherited auth header policy
1 parent 2843964 commit c678a20

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

src/agents/models-config.skips-writing-models-json-no-env-token.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ describe("models-config", () => {
228228
baseUrl: "https://botzhipin.work/openclaw/platform/v1",
229229
apiKey: "main-agent-api-key",
230230
auth: "api-key",
231-
authHeader: false,
231+
authHeader: true,
232232
api: "openai-completions",
233233
headers: {
234234
Authorization: "Bearer main-agent-token",
@@ -262,6 +262,7 @@ describe("models-config", () => {
262262
botzhipin: {
263263
baseUrl: "https://botzhipin.work/openclaw/platform/v1",
264264
auth: "api-key",
265+
authHeader: true,
265266
api: "openai-completions",
266267
models: [
267268
{

src/agents/models-config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ async function writeModelsFileAtomicIfMissing(
296296

297297
const INHERITED_MODELS_JSON_PROVIDER_CREDENTIAL_FIELDS = new Set([
298298
"apiKey",
299-
"authHeader",
300299
"headers",
301300
"keyRef",
302301
"proxy",

src/agents/sessions/model-registry.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,34 @@ describe("ModelRegistry models.json auth", () => {
140140
});
141141
});
142142

143+
it("injects Authorization header from stored auth when authHeader is true", async () => {
144+
const modelsPath = writeModelsJson({
145+
providers: {
146+
custom: {
147+
baseUrl: "https://models.example/v1",
148+
auth: "api-key",
149+
authHeader: true,
150+
api: "openai-responses",
151+
models: [{ id: "example-model" }],
152+
},
153+
},
154+
});
155+
156+
const registry = ModelRegistry.create(
157+
AuthStorage.inMemory({ custom: { type: "api_key", key: "sk-test" } }),
158+
modelsPath,
159+
);
160+
const model = registry.find("custom", "example-model");
161+
162+
expect(registry.getError()).toBeUndefined();
163+
expect(model).toBeDefined();
164+
await expect(registry.getApiKeyAndHeaders(model!)).resolves.toEqual({
165+
ok: true,
166+
apiKey: "sk-test",
167+
headers: { Authorization: "Bearer sk-test" },
168+
});
169+
});
170+
143171
it("loads provider models from generated plugin catalog shards", () => {
144172
const modelsPath = writeModelsJsonWithPluginCatalog({
145173
root: { providers: {} },

0 commit comments

Comments
 (0)