Skip to main content
m serve runs any Mellea program as an OpenAI-compatible chat endpoint. This lets any LLM client — LangChain, the OpenAI SDK, curl — call your Mellea program as if it were a model. Prerequisites: pip install "mellea[server]".

The serve() function

Your program must define a serve() function with this signature:
m serve loads your file, finds serve(), and routes incoming requests to it. ChatMessage has role and content fields matching the OpenAI chat format.

Example serve program

The session is initialised at module level so it is reused across requests. This preserves the ChatContext conversation history across turns.

Starting m serve

The server starts on port 8000 by default and exposes:
  • POST /v1/chat/completions — OpenAI-compatible chat completions endpoint
  • GET /health — health check
To see all options:

Calling the served endpoint

Any OpenAI-compatible client works. Using curl:
Using the OpenAI Python SDK:
Full example: docs/examples/m_serve/m_serve_example_simple.py
See also: Context and Sessions | Backends and Configuration | CLI Reference