gitbutlerapp/gitbutler · error

LM Studio API error ( )

Error message

LM Studio API error (${response.status}): ${errorText}

What it means

After POSTing to the LM Studio chat completions endpoint, a non-2xx HTTP status triggers this error, embedding the status code and the raw response body. It means LM Studio (or the proxy) rejected the request server-side.

Solutions

  1. Read the errorText in the message for the server's reason and fix the request accordingly.
  2. Verify the model name matches a loaded model in LM Studio.
  3. Confirm the endpoint URL points at LM Studio's OpenAI-compatible API (typically http://localhost:1234/v1).
  4. Check LM Studio server logs for the corresponding error.

Example fix

// before
const client = new LMStudioClient('http://localhost:1234', 'mistral-7b');
// after (include /v1 base and a loaded model id)
const client = new LMStudioClient('http://localhost:1234/v1', 'mistral-7b-instruct-v0.2');
Defensive patterns

Strategy: try-catch

Validate before calling

const health = await fetch(endpoint + '/models');
if (!health.ok) throw new Error(`LM Studio endpoint unhealthy: ${health.status}`);

Try / catch

try {
  await client.evaluate(prompt);
} catch (e) {
  const m = e.message.match(/LM Studio API error \((\d+)\): (.*)/s);
  if (m) {
    const [_, status, body] = m;
    // handle 404 (wrong model/endpoint), 400 (bad payload), 5xx (server error)
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: The fetch to {endpoint}/chat/completions resolves but response.ok is false — e.g. 404 because the model name is wrong, 400 for a malformed payload, 500 when the local server errors.

Common situations: Model not loaded in LM Studio or wrong model name; LM Studio server returning 404 because the endpoint URL includes/omits /v1 incorrectly; requesting an unavailable context length; server overloaded or crashed mid-request.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/062bc65a045cf082. Report an issue: GitHub.

Appendix: source

Thrown at apps/desktop/src/lib/ai/lmStudioClient.ts:69

			// Make request to the LM Studio API
			const response = await fetch(`${this.baseUrl}/chat/completions`, {
				method: "POST",
				headers: {
					"Content-Type": "application/json",
				},
				body: JSON.stringify({
					model: this.modelName,
					messages: messages,
					temperature: DEFAULT_TEMPERATURE,
					max_tokens: options?.maxTokens ?? DEFAULT_MAX_TOKENS,
					stream: shouldStream,
				}),
			});

			if (!response.ok) {
				const errorText = await response.text();
				throw new Error(`LM Studio API error (${response.status}): ${errorText}`);
			}

			// Handle streaming response
			if (shouldStream) {
				const reader = response.body?.getReader();
				if (!reader) {
					throw new Error("Failed to get reader from response");
				}

				let result = "";
				const decoder = new TextDecoder();

				while (true) {
					const { done, value } = await reader.read();
					if (done) break;

					const chunk = decoder.decode(value, { stream: true });
					const lines = chunk

View on GitHub (pinned to 58e5313667)