Skip to content

[bug] Incorrect API endpoint handling in LM Studio's server. #618

Description

@mirpo

Which version of LM Studio?

LM Studio 0.3.14

Which operating system?

Mac

What is the bug?

Incorrect API endpoint handling in LM Studio's server. When attempting to use the /chat/completions endpoint (without the /v1/ prefix), the server returns a 200 OK response with an error message instead of the appropriate 404 status code.

Technical details

When making a POST request to http://localhost:1234/chat/completions, the server responds with a 200 OK status code but returns an error message:

{"error":"Unexpected endpoint or method. (POST /chat/completions)"}

The correct endpoint that works is http://localhost:1234/v1/chat/completions, following the OpenAI API format.

Screenshots


Logs

< HTTP/1.1 200 OK
< X-Powered-By: Express
< Content-Type: application/json; charset=utf-8
< Content-Length: 67
< ETag: W/"43-qTdCaLfEMe8wb/ShYO0yTUTunEg"
< Date: Fri, 25 Apr 2025 18:22:52 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
<
* Connection #0 to host localhost left intact
{"error":"Unexpected endpoint or method. (POST /chat/completions)"}

To Reproduce

  1. Start LM Studio server on port 1234
  2. Run the following curl command:
curl --verbose http://localhost:1234/chat/completions \
    -H "Content-Type: application/json" \
    -d '{
        "model": "any-model-name",
        "messages": [
            { "role": "system", "content": "Always answer in rhymes. Today is Thursday" },
            { "role": "user", "content": "What day is it today?" }
        ],
        "temperature": 0.7,
        "max_tokens": -1,
        "stream": false
    }'
  1. Observe that the server returns a 200 OK status with an error message
    {"error":"Unexpected endpoint or method. (POST /chat/completions)"}

Expected behavior

The server should either:

  1. Return a 404 status code for invalid endpoints, or
  2. Support both /chat/completions and /v1/chat/completions as valid endpoints

Working example

The following endpoint works correctly:

curl --verbose http://localhost:1234/v1/chat/completions \
    -H "Content-Type: application/json" \
    -d '{
        "model": "any-model-name",
        "messages": [
            { "role": "system", "content": "Always answer in rhymes. Today is Thursday" },
            { "role": "user", "content": "What day is it today?" }
        ],
        "temperature": 0.7,
        "max_tokens": -1,
        "stream": false
    }'

Additional information

This issue can cause confusion for developers transitioning from other API implementations or following older documentation. The server responds with a success status code (200) despite the request failing, which violates HTTP conventions and makes error handling more difficult for client applications.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions