Skip to content

Commit a9bfe9e

Browse files
committed
fix: Add missing API Key headers if provided in settings
1 parent fd6d6f6 commit a9bfe9e

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

tools/server/public/index.html.gz

66 Bytes
Binary file not shown.

tools/server/webui/src/lib/services/chat.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,14 @@ export class ChatService {
150150
}
151151

152152
try {
153+
const currentConfig = config();
154+
const apiKey = currentConfig.apiKey?.toString().trim();
155+
153156
const response = await fetch(`/v1/chat/completions`, {
154157
method: 'POST',
155158
headers: {
156-
'Content-Type': 'application/json'
159+
'Content-Type': 'application/json',
160+
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {})
157161
},
158162
body: JSON.stringify(requestBody),
159163
signal: this.abortController.signal
@@ -505,9 +509,13 @@ export class ChatService {
505509
*/
506510
static async getServerProps(): Promise<ApiLlamaCppServerProps> {
507511
try {
512+
const currentConfig = config();
513+
const apiKey = currentConfig.apiKey?.toString().trim();
514+
508515
const response = await fetch(`/props`, {
509516
headers: {
510-
'Content-Type': 'application/json'
517+
'Content-Type': 'application/json',
518+
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {})
511519
}
512520
});
513521

tools/server/webui/src/lib/services/slots.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,14 @@ export class SlotsService {
135135
}
136136

137137
try {
138-
const response = await fetch('/slots');
138+
const currentConfig = config();
139+
const apiKey = currentConfig.apiKey?.toString().trim();
140+
141+
const response = await fetch('/slots', {
142+
headers: {
143+
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {})
144+
}
145+
});
139146
if (response.ok) {
140147
const slotsData = await response.json();
141148
if (Array.isArray(slotsData) && slotsData.length > 0) {

tools/server/webui/src/lib/stores/server.svelte.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ChatService } from '$lib/services/chat';
2+
import { config } from '$lib/stores/settings.svelte';
23

34
/**
45
* ServerStore - Server state management and capability detection
@@ -94,7 +95,14 @@ class ServerStore {
9495
}
9596

9697
try {
97-
const response = await fetch('/slots');
98+
const currentConfig = config();
99+
const apiKey = currentConfig.apiKey?.toString().trim();
100+
101+
const response = await fetch('/slots', {
102+
headers: {
103+
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {})
104+
}
105+
});
98106

99107
if (response.status === 501) {
100108
console.info('Slots endpoint not implemented - server started without --slots flag');

0 commit comments

Comments
 (0)