{"slug": "serving-any-llm-using-a-single-command-line-with-flama", "title": "Serving any LLM using a single command line with Flama", "summary": "Flama 2.0 introduces first-class support for generative AI, enabling users to download, package, and serve large language models (LLMs) via a single command line. The framework allows fetching models from HuggingFace, interacting with them locally, and serving them over HTTP with a production-ready API and built-in chat interface. Flama's CLI commands like `flama get`, `flama model run`, and `flama serve` streamline the entire workflow without requiring boilerplate code or custom infrastructure.", "body_md": "[Flama 2.0](https://dev.to/vortico/--2pll) brings first-class support for generative AI: downloading, packaging, and serving large language models (LLMs) is now as simple as running a few commands in your terminal. No boilerplate code, no custom serving infrastructure, no\n\nconfiguration files. Just the CLI and a model.\n\nIn this post, we walk through the entire workflow: fetching a model from HuggingFace, interacting with it locally in your terminal, and serving it over HTTP with a production-ready API and a built-in chat interface. We will also show how a locally served model can power agentic workflows, using Claude CLI as a practical example.\n\nBefore we dive into the details, we recommend you to have the following resources at hand:\n\n`flama get`\n\n`flama model run`\n\n`flama model stream`\n\n`flama serve`\n\ncommand`flama get`\n\nThe first step in serving an LLM with Flama is downloading and packaging a model into a `.flm`\n\nartifact (a *Flama Lightweight Model* file). The `flama get`\n\ncommand handles this in a single step: it downloads the model weights and configuration from a supported source and serialises them into the portable `.flm`\n\nformat.\n\nAll examples in this post assume Flama has been installed with the LLM extras via [uv](https://docs.astral.sh/uv/):\n\n```\nuv pip install \"flama[llm,pydantic]\"\n```\n\nAlternatively, you can run any command without a prior install by using `uvx --from \"flama[llm,pydantic]\" flama ...`\n\n, but for brevity we assume Flama is already installed throughout.\n\nLet us fetch a quantised version of Google's Gemma 4 model, optimised for Apple Silicon via the MLX Community:\n\n```\nflama get --family llm --source huggingface mlx-community/gemma-4-E2B-it-qat-4bit\n\nDownloading ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 2.3 GB 28.7 MB/s 0:00:00\nPackaging...\nModel saved to mlx-community_gemma-4-E2B-it-qat-4bit.flm\n```\n\nTwo options are required: `--source`\n\ntells Flama where to download from (currently HuggingFace), and `--family`\n\ndeclares whether the artifact is a traditional machine-learning model (`ml`\n\n) or a generative model (`llm`\n\n). For large language models, you always pass `--family llm`\n\n.\n\nThe output path defaults to `<model-name>.flm`\n\nwith slashes replaced by underscores. If you prefer a custom path, pass `--output`\n\n:\n\n```\nflama get --family llm --source huggingface mlx-community/gemma-4-E2B-it-qat-4bit --output models/gemma.flm\n```\n\nWhen you run `flama get`\n\n, the following happens:\n\n`--max-concurrent`\n\n).`.flm`\n\narchive alongside a manifest that records the model family, the originating library, and metadata such as the model name and creation timestamp.The result is a self-contained, portable artifact. The `.flm`\n\nformat is framework-agnostic: the same file runs on vLLM (Linux with CUDA) or MLX (Apple Silicon), with Flama selecting the appropriate backend at load time based on what is available in the environment.\n\nOnce you have a packaged `.flm`\n\nartifact, you can interact with it directly from your terminal using the `flama model`\n\ncommand. No server, no HTTP, no code. This is invaluable for quick testing, prompt experimentation, and pipeline scripting.\n\n`flama model run`\n\nThe `run`\n\nsub-command sends a prompt to the model, waits for the full response, and prints it:\n\n```\necho \"What is Flama?\" | flama model mlx-community_gemma-4-E2B-it-qat-4bit.flm run --system \"Be concise.\"\n\nFlama is a Python framework for building production-ready APIs with a focus on machine learning and generative AI, enabling one-line model serving behind HTTP endpoints.\n```\n\nYou can tune generation with `--param`\n\nflags:\n\n```\necho \"Explain dependency injection in three sentences.\" | \\\n  flama model mlx-community_gemma-4-E2B-it-qat-4bit.flm run \\\n    --system \"You are a software engineering instructor.\" \\\n    --param temperature=0.7 \\\n    --param max_tokens=256\n```\n\nFor multi-turn conversations, use the `--transport conversation`\n\nflag and pass a JSON message list:\n\n```\necho '[{\"role\": \"user\", \"content\": \"Hi!\"}, {\"role\": \"assistant\", \"content\": \"Hello! How can I help?\"}, {\"role\": \"user\", \"content\": \"What is an API?\"}]' | \\\n  flama model mlx-community_gemma-4-E2B-it-qat-4bit.flm run --transport conversation\n```\n\n`flama model stream`\n\nFor an interactive, token-by-token experience (especially useful with larger responses), use `stream`\n\ninstead of `run`\n\n. Tokens are printed as they are generated, giving you immediate feedback:\n\n```\necho \"What is flama (python package)?\" | \\\n  flama model mlx-community_gemma-4-E2B-it-qat-4bit.flm stream --system \"Be concise.\"\n\nFlama is a Python framework for building production-ready ML and generative AI APIs. It lets you serve models behind HTTP endpoints with minimal code, supporting HuggingFace, vLLM, and MLX backends, OpenAI/Anthropic/Ollama-compatible protocols, built-in chat interfaces, and the Model Context Protocol for agent tooling.\n```\n\nThe streaming output appears progressively in your terminal, character by character, making it feel like a real conversation. This is especially satisfying when working with models that produce longer, more detailed responses.\n\nYou can also ask the model about itself and the framework it runs on:\n\n```\necho \"How do I serve an ML model with Flama?\" | \\\n  flama model mlx-community_gemma-4-E2B-it-qat-4bit.flm stream \\\n    --system \"You are a helpful assistant that knows about the Flama Python framework.\"\n```\n\nIf you want to see multiple output channels (for instance, reasoning and output), pass `--channel`\n\n:\n\n```\necho \"Solve step by step: what is 23 * 47?\" | \\\n  flama model mlx-community_gemma-4-E2B-it-qat-4bit.flm stream \\\n    --channel thinking --channel output\n```\n\nThe true power of Flama lies in going from a local model to a production-ready HTTP API in a single command. No Python code, no configuration files, no Docker images. Just `flama serve`\n\n.\n\n`flama serve`\n\ncommand\nTo serve the model we downloaded earlier:\n\n```\nflama serve --model file=mlx-community_gemma-4-E2B-it-qat-4bit.flm,url=/,name=gemma\n\nINFO:     Started server process [52341]\nINFO:     Waiting for application startup.\nINFO:     Model starting (name: gemma)\nINFO:     Model ready (name: gemma)\nINFO:     Application startup complete.\nINFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)\n```\n\nThat is it. A single command and your model is live behind a full HTTP API. Let us unpack what `--model`\n\naccepts:\n\n`file`\n\n`.flm`\n\nartifact.`url`\n\n`/`\n\n).`name`\n\n`serving`\n\n`native,openai,anthropic,ollama`\n\n). When omitted, all dialects are mounted.`params`\n\n`temperature=0.7`\n\n).You can serve multiple models in a single application:\n\n```\nflama serve \\\n  --model file=gemma.flm,url=/gemma,name=gemma,serving=native+openai \\\n  --model file=qwen.flm,url=/qwen,name=qwen,serving=native+anthropic\n```\n\nAnd you can configure the server with the usual options:\n\n```\nflama serve \\\n  --model file=mlx-community_gemma-4-E2B-it-qat-4bit.flm,url=/,name=gemma \\\n  --server-host 0.0.0.0 \\\n  --server-port 9000 \\\n  --app-title \"My LLM API\" \\\n  --app-docs /docs/\n```\n\nWhen the native serving dialect is enabled (which it is by default), your model comes with a built-in chat interface accessible at the `/chat/`\n\nroute (relative to the model's URL prefix). If you served the model at `/`\n\n, then navigate to `http://127.0.0.1:8000/chat/`\n\nYou will be greeted with a polished, production-quality chat interface where you can type prompts and watch the model's responses stream in token by token. The interface renders Markdown, LaTeX math (via KaTeX), and Mermaid diagrams out of the box, so technical answers look exactly as intended.\n\nThe chat interface requires no frontend code, no build step, and no external dependencies. It is a self-contained single-page application served directly from the framework. Every model you serve gets its own chat window (e.g., `/gemma/chat/`\n\n, `/qwen/chat/`\n\n), each connected to its respective model's streaming endpoint.\n\nOne of the most compelling use cases for a locally served LLM is powering agentic workflows. Because Flama exposes your model through industry-standard protocols (OpenAI, Anthropic, Ollama), any tool that speaks those protocols can use your local model as its backend.\n\nA practical example is using the [Claude CLI](https://docs.anthropic.com/en/docs/claude-code) with a local model served by Flama. Instead of sending your prompts to Anthropic's servers, you can route them through your own locally-running\n\nmodel.\n\nFirst, make sure your model is serving with the Anthropic dialect enabled:\n\n```\nflama serve --model file=mlx-community_gemma-4-E2B-it-qat-4bit.flm,url=/,name=gemma,serving=native+anthropic\n```\n\nThen, configure Claude CLI to use your local Flama endpoint by adding the following to your `~/.claude/settings.json`\n\n(or `.claude/settings.local.json`\n\nfor a project-specific override):\n\n```\n{\n  \"env\": {\n    \"ANTHROPIC_BASE_URL\": \"http://127.0.0.1:8000/anthropic\",\n    \"ANTHROPIC_DEFAULT_SONNET_MODEL\": \"gemma\",\n    \"ANTHROPIC_DEFAULT_OPUS_MODEL\": \"gemma\",\n    \"ANTHROPIC_DEFAULT_HAIKU_MODEL\": \"gemma\"\n  }\n}\n```\n\nWith this configuration in place, simply launch Claude CLI as usual:\n\n```\nclaude\n```\n\nClaude CLI will now route all its requests through your local Flama-served model instead of Anthropic's cloud. Here is\n\nwhat a typical interaction looks like:\n\n```\n❯ claude\n\nWhat is this repo about?\n\n∴ Thinking…\n\n  The user is asking what the repository is about.\n  I should use the Agent tool to perform a general-purpose search or exploration,\n  as this is a broad question about the project's context.\n\n⏺ Agent(Find out what the repository is about)\n  ⎿  Done (2 tool uses · 14.5k tokens · 36s)\n\n∴ Thinking…\n\n  The agent returned a detailed summary of the project, which is a Python library\n  called \"Flama\" for developing and deploying APIs, especially ML APIs, focusing\n  on simplifying boilerplate code while providing robust features like schema\n  validation, dependency injection, and automatic documentation.\n\n⏺ The repository is a Python library called Flama, which provides a framework\n  for developing and deploying APIs, with a special focus on Machine Learning\n  (ML) applications.\n\n  It aims to make deploying ML APIs \"ridiculously simple\" by simplifying\n  boilerplate code while offering robust features such as:\n  - API development for GraphQL, REST, and ML endpoints.\n  - Resource handling with CRUD methods over SQLAlchemy tables.\n  - Schema validation for inputs and outputs.\n  - Dependency Injection via Components.\n  - Automatic generation of OpenAPI documentation (Swagger UI, ReDoc).\n\n  What specific part of the framework or implementation would you like to explore next?\n```\n\nYour agentic tasks (code generation, file editing, research) run entirely on your local hardware. This gives you:\n\nThis same pattern works with any agent framework that supports custom API base URLs: LangChain, CrewAI, AutoGen, or any\n\ncustom tool that accepts a base URL configuration.\n\nFlama 2.0 makes the journey from \"I want to use an LLM\" to \"I have a production-ready API\" as short as possible. The CLI provides three levels of interaction:\n\n`flama get`\n\n`.flm`\n\nartifact.`flama model`\n\n`flama serve`\n\nNo boilerplate Python code, no YAML configuration, no container orchestration. Just the CLI.\n\nThe fact that Flama speaks the protocols your tools already understand (OpenAI, Anthropic, Ollama) means that adopting a local model in your workflow requires changing nothing but a base URL. Your existing SDKs, agent frameworks, and chat interfaces work without modification.\n\nIn upcoming posts, we will explore how to build MCP servers with Flama to expose tools and resources to AI agents, and how to combine LLM serving with the Model Context Protocol for truly powerful agentic applications.\n\nIf you find Flama useful for building robust Machine Learning and Generative AI APIs, we'd be thrilled if you showed your support by giving us a ⭐ on [GitHub](https://github.com/vortico/flama). Your stars are the best fuel for our development efforts!\n\nYou can also stay updated with the latest news and development threads by following us on [𝕏](https://x.com/VorticoTech).\n\n[Vortico](https://vortico.tech/): We specialize in software development, helping businesses enhance and expand their AI and technology capabilities.", "url": "https://wpnews.pro/news/serving-any-llm-using-a-single-command-line-with-flama", "canonical_source": "https://dev.to/vortico/serving-any-llm-using-a-single-command-line-with-flama-2j5", "published_at": "2026-06-16 19:37:10+00:00", "updated_at": "2026-06-16 20:17:34.665384+00:00", "lang": "en", "topics": ["large-language-models", "developer-tools", "ai-infrastructure", "generative-ai", "mlops"], "entities": ["Flama", "HuggingFace", "Google", "Gemma 4", "MLX Community", "Apple Silicon", "vLLM", "CUDA"], "alternates": {"html": "https://wpnews.pro/news/serving-any-llm-using-a-single-command-line-with-flama", "markdown": "https://wpnews.pro/news/serving-any-llm-using-a-single-command-line-with-flama.md", "text": "https://wpnews.pro/news/serving-any-llm-using-a-single-command-line-with-flama.txt", "jsonld": "https://wpnews.pro/news/serving-any-llm-using-a-single-command-line-with-flama.jsonld"}}