Skip to content

feat(server): add Anthropic-style /v1/messages API endpoint #73

Closed

Description

@inureyes

mlxcel-server exposes an OpenAI-compatible API (chat completions and the Responses API), but it has no Anthropic Messages-style endpoint, so clients written against the Anthropic Messages schema cannot talk to mlxcel-server without a translation shim.

Goal

Add a POST /v1/messages endpoint (with a /messages alias) that accepts the Anthropic Messages request schema and returns Anthropic-style responses, in both synchronous and SSE streaming modes. Add POST /v1/messages/count_tokens (with a /messages/count_tokens alias) for prompt token counting.

Scope

  • Request schema: top-level system (string or text-block array), messages, max_tokens, stop_sequences, temperature / top_p / top_k, function tools + tool_choice, and thinking.
  • Content blocks: text, image (base64 and url), tool_use, and tool_result, including image content nested inside tool_result blocks so vision models can consume tool-produced images.
  • Streaming: emit the Anthropic SSE event sequence (message_start, content_block_start / delta / stop, message_delta, message_stop, error), with usage populated on both the non-streaming response and the streaming message_delta.
  • Reuse the existing generation, chat-template, media, tool-call, and thinking-budget plumbing rather than duplicating the generation loop. Translate the Anthropic request into the server's internal chat-completion representation, and assemble Anthropic content blocks on the way out, structured similarly to the existing Responses API endpoint.
  • Map stop reasons and apply stop-sequence truncation consistent with the Anthropic schema.
  • Bound the count_tokens path against unbounded tool arrays so it cannot be used to exhaust server resources.

Acceptance criteria

  • POST /v1/messages handles both sync and streaming requests and returns schema-valid Anthropic responses.
  • POST /v1/messages/count_tokens returns a prompt token count and rejects oversized tool arrays.
  • Images supplied directly and images nested inside tool_result blocks both reach vision models.
  • Non-streaming and streaming responses both populate usage.
  • Unit tests cover request translation, content-block assembly, stop-reason mapping, and the streaming state machine.

Activity

  1. added
    type:enhancement
    area:inference
    priority:medium
    status:ready
    on May 24, 2026
  2. self-assigned this
    on May 29, 2026
  3. added this to the 0.1 milestone on Jun 5, 2026
  4. added
    status:done
    and removed
    status:ready
    on Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:inferencepriority:mediumstatus:donetype:enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions