The Messages API carries a conversation as user and assistant messages. LM Studio's Anthropic-compatible API lets a local model answer those requests without sending them to Anthropic.
Compatibility describes the request and response format, rather than the model provider. The request names a local model instead of Claude, and the reply contains typed content blocks instead of an OpenAI-style choices array.
curl can send a Messages request directly, so an Anthropic account or SDK is unnecessary. The LM Studio service, HTTP server, and a loaded chat model must already be available on the same machine.
Steps to call the Anthropic-compatible API in LM Studio:
- Check the local LM Studio server's port. Example output:
$ lms server status The server is running on port 1234.
The request below uses 127.0.0.1:1234. A server on another port needs that port in the URL. On a headless Linux host, the daemon setup provides lms and starts the loopback HTTP server.
Related: How to run LM Studio headlessly with llmster - Find your loaded chat model's identifier. Example output:
$ lms ps IDENTIFIER MODEL STATUS SIZE CONTEXT PARALLEL LOAD CONFIG DEVICE TTL local-chat qwen2.5-0.5b-instruct IDLE 397.81 MB 2048 4 LM Studio Local 59m / 1h
The IDENTIFIER column supplies the request's model value. A downloaded file alone is insufficient; an empty list means no model instance is loaded.
Related: How to load a model with lms in LM Studio - Send a Messages request using your model's identifier in place of local-chat.
$ curl --fail-with-body --silent --show-error \ http://127.0.0.1:1234/v1/messages \ -H 'Content-Type: application/json' \ -d '{ "model": "local-chat", "max_tokens": 64, "messages": [ {"role": "user", "content": "Say hello in one short sentence."} ] }'Example output:
{ "id": "msg_g2si583api7pifgkq5jz", "type": "message", "role": "assistant", "content": [ { "type": "text", "text": "Hello! How can I assist you today?" } ], "model": "local-chat", "stop_reason": "end_turn", "stop_sequence": null, "usage": { "input_tokens": 36, "output_tokens": 10, "cache_read_input_tokens": 24 } }-d sends a POST request, and max_tokens limits the reply length. The response names your model and carries generated text in content, with type set to message and role set to assistant. Reply text, IDs, and token counts vary; API compatibility does not guarantee answer accuracy. With Require Authentication disabled, no x-api-key header is needed. The loopback URL stays on this machine; exposing an unauthenticated server lets network clients use the model.
Related: LM Studio Messages endpoint reference