### Manual Installation of MiMo2API Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Steps for manual installation including virtual environment setup, dependency installation, configuration, and starting the service. ```bash # 1. Create virtual environment python3 -m venv venv source venv/bin/activate # 2. Install dependencies pip install -r requirements.txt # 3. Create config file cp config.example.json config.json # 4. Start python main.py ``` -------------------------------- ### Install Dependencies Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Installs the Python dependencies required for MiMo2API using pip. ```bash pip install -r requirements.txt ``` -------------------------------- ### Start MiMo2API in Foreground Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Starts the MiMo2API service in the foreground. Press Ctrl+C to stop. ```bash # Foreground (Ctrl+C to stop) ./venv/bin/python main.py ``` -------------------------------- ### Authentication Methods Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Examples of using the 'x-api-key' header and the backward-compatible 'Authorization: Bearer' header for authentication. ```bash # x-api-key (native Anthropic) curl -H "x-api-key: sk-mimo" ... ``` ```bash # Authorization Bearer (backward compatible) curl -H "Authorization: Bearer sk-mimo" ... ``` -------------------------------- ### Function Calling Response Example Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Example of a successful function call response from the API, indicating the `finish_reason` and the structured `tool_calls`. ```json { "choices": [{ "finish_reason": "tool_calls", "message": { "role": "assistant", "content": null, "tool_calls": [{ "id": "call_abc123...", "type": "function", "function": { "name": "get_weather", "arguments": "{\"city\": \"北京\"}" } }] } }] } ``` -------------------------------- ### MiMo2API Configuration Example Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Shows a sample configuration file for MiMo2API, including API keys and account details. ```json { "api_keys": "sk-mimo,sk-another", "mimo_accounts": [ { "service_token": "eyJ...", "user_id": "123456", "xiaomichatbot_ph": "abc123...", "is_valid": true, "login_time": "04-26 17:00", "last_test": "04-26 17:05" } ], "models": [] } ``` -------------------------------- ### Clone and Deploy MiMo2API Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Use this command to clone the repository and run the deployment script for a quick setup. ```bash git clone https://github.com/Fly143/MiMo2API.git cd MiMo2API chmod +x deploy.sh ./deploy.sh ``` -------------------------------- ### Start MiMo2API in Background Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Starts the MiMo2API service in the background and redirects output to a log file. Stores the process ID (PID) in mimo.pid. ```bash # Background nohup ./venv/bin/python main.py > mimo.log 2>&1 & echo $! > mimo.pid ``` -------------------------------- ### MiMoML Prompt Injection for Tool Calls Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Example of how OpenAI tool definitions are converted to MiMoML format and injected into the system message for tool invocation. ```xml <|MiMoML|tool_calls> <|MiMoML|invoke name="get_weather"> <|MiMoML|parameter name="city"> ``` -------------------------------- ### GET /v1/messages/batches Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md List all created batch tasks. ```APIDOC ## GET /v1/messages/batches ### Description List all batch tasks that have been created. ### Method GET ### Endpoint /v1/messages/batches ### Parameters #### Header Parameters - **x-api-key** (string) - Required - API key for authentication. ### Response #### Success Response (200) - **batches** (array) - An array of batch objects. #### Response Example ```json { "batches": [ {"batch_id": "batch_xyz789", "status": "processing"} ] } ``` ``` -------------------------------- ### Tool Calling Response Format Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Example of the JSON response when a tool is called. The response includes a 'tool_use' content block with the tool's ID, name, and input. ```json { "content": [ {"type": "tool_use", "id": "tu_xxx", "name": "get_time", "input": {}} ], "stop_reason": "tool_use" } ``` -------------------------------- ### Function Calling for Structured Output Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Utilize function calling to get structured output from the model. The model can identify when a function should be called and return the arguments. ```bash curl http://localhost:8080/v1/chat/completions \ -H "Authorization: Bearer sk-mimo" \ -H "Content-Type: application/json" \ -d '{ "model": "mimo-v2-pro", "messages": [ {"role": "user", "content": "What is the weather in Beijing today?"} ], "tools": [{ "type": "function", "function": { "name": "get_weather", "description": "Query weather for a specified city", "parameters": { "type": "object", "properties": { "city": {"type": "string", "description": "City name"} }, "required": ["city"] } } }], "tool_choice": "auto" }' ``` -------------------------------- ### GET /v1/messages/batches/{batch_id} Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Retrieve detailed information about a specific batch task. ```APIDOC ## GET /v1/messages/batches/{batch_id} ### Description Get detailed information about a specific batch task. ### Method GET ### Endpoint /v1/messages/batches/{batch_id} ### Parameters #### Path Parameters - **batch_id** (string) - Required - The unique identifier of the batch task. #### Header Parameters - **x-api-key** (string) - Required - API key for authentication. ### Response #### Success Response (200) - **batch_details** (object) - Detailed information about the batch task. #### Response Example ```json { "batch_details": { "batch_id": "batch_xyz789", "status": "completed", "results_url": "/v1/messages/batches/batch_xyz789/results" } } ``` ``` -------------------------------- ### GET /v1/messages/batches/{batch_id}/results Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Download the results of a completed batch task in JSONL format. ```APIDOC ## GET /v1/messages/batches/{batch_id}/results ### Description Download the results of a completed batch task. The results are provided in JSON Lines (JSONL) format. ### Method GET ### Endpoint /v1/messages/batches/{batch_id}/results ### Parameters #### Path Parameters - **batch_id** (string) - Required - The unique identifier of the batch task. #### Header Parameters - **x-api-key** (string) - Required - API key for authentication. ### Response #### Success Response (200) - **results** (string) - The batch results in JSONL format. #### Response Example ```jsonl {"result": "..."} {"result": "..."} ``` ``` -------------------------------- ### MiMo2API Responses API - Non-streaming Request Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Example of a non-streaming request to the MiMo2API Responses API. This demonstrates the basic usage for sending a user input and receiving a response. ```bash curl http://localhost:8080/v1/responses \ -H "Authorization: Bearer sk-mimo" \ -H "Content-Type: application/json" \ -d '{ "model": "mimo-v2-pro", "input": [{"role": "user", "content": "Hello"}] }' ``` -------------------------------- ### GET /v1/messages/{message_id} Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Retrieve a previously stored message by its unique identifier. ```APIDOC ## GET /v1/messages/{message_id} ### Description Retrieve a stored message using its unique identifier. ### Method GET ### Endpoint /v1/messages/{message_id} ### Parameters #### Path Parameters - **message_id** (string) - Required - The unique identifier of the message to retrieve. #### Header Parameters - **x-api-key** (string) - Required - API key for authentication. ### Response #### Success Response (200) - **message** (object) - The retrieved message object. #### Response Example ```json { "message": { "id": "msg_abc123", "role": "assistant", "content": "This is a stored message." } } ``` ``` -------------------------------- ### MiMo2API Responses API - Streaming Request Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Example of a streaming request to the MiMo2API Responses API using Server-Sent Events (SSE). This is used for receiving responses in real-time chunks. ```bash curl http://localhost:8080/v1/responses \ -H "Authorization: Bearer sk-mimo" \ -H "Content-Type: application/json" \ -d '{ "model": "mimo-v2-pro", "input": [{"role": "user", "content": "Tell me a story"}], "stream": true }' ``` -------------------------------- ### Anthropic Messages API (Non-streaming) Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Make a request using the Anthropic Messages API format by changing the endpoint and API key header. This example shows a non-streaming request. ```bash # Non-streaming curl -X POST http://localhost:8080/v1/messages \ -H "x-api-key: sk-mimo" \ -H "Content-Type: application/json" \ -H "anthropic-version: 2023-06-01" \ -d '{ "model": "mimo-v2-flash", "max_tokens": 1024, "messages": [ {"role": "user", "content": "Hello"} ] }' ``` -------------------------------- ### Tool Calling with curl Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Demonstrates how to call a tool using the Responses API. Note the 'tools' format differs slightly from Chat Completions API. ```bash curl http://localhost:8080/v1/responses \ -H "Authorization: Bearer sk-mimo" \ -H "Content-Type: application/json" \ -d '{ "model": "mimo-v2-pro", "input": [{"role": "user", "content": "What time is it?"}], "tools": [{ "type": "function", "name": "get_time", "description": "Get current time", "parameters": { "type": "object", "properties": { "timezone": {"type": "string"} } } }] }' ``` -------------------------------- ### File Upload for Text Analysis Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Upload a text file (e.g., .md, .txt) and have MiMo read its content for analysis. The file content is base64 encoded. ```bash # Read file and encode as base64 BASE64=$(base64 -w0 yourfile.md) curl http://localhost:8080/v1/chat/completions \ -H "Authorization: Bearer sk-mimo" \ -H "Content-Type: application/json" \ -d "{ \"model\": \"mimo-v2-pro\", \"messages\": [{\"role\": \"user\", \"content\": [{\"type\": \"text\", \"text\": \"Summarize this file\"},{\"type\": \"file\", \"file\": {\"filename\": \"yourfile.md\", \"file_data\": \"$BASE64\"}}]}] }" ``` -------------------------------- ### Run MiMo2API with Docker Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Deploy MiMo2API using a Docker container, mapping the configuration file and exposing the service port. ```bash docker run -d -p 8080:8080 -v $(pwd)/config.json:/app/config.json ghcr.io/fly143/mimo2api:latest ``` -------------------------------- ### List Available Models via API Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Use this cURL command to query the API for a list of all available MiMo official models. ```bash curl http://localhost:8080/v1/models \ -H "Authorization: Bearer sk-mimo" ``` -------------------------------- ### Tool Calling with cURL Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Send a message with tool definitions to enable the model to call tools. The 'tools' parameter accepts a list of tool definitions. ```bash curl -X POST http://localhost:8080/v1/messages \ -H "x-api-key: sk-mimo" \ -H "Content-Type: application/json" \ -H "anthropic-version: 2023-06-01" \ -d '{ "model": "mimo-v2-flash", "max_tokens": 1024, "messages": [ {"role": "user", "content": "What time is it?"} ], "tools": [{ "name": "get_time", "description": "Get current time", "input_schema": {"type": "object", "properties": {}} }] }' ``` -------------------------------- ### List Models Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Retrieves a list of all currently available MiMo official models. ```APIDOC ## List Models ### Description Retrieves a list of all currently available MiMo official models. ### Method GET ### Endpoint /v1/models ### Parameters #### Headers - **Authorization** (string) - Required - Bearer token (e.g., "Bearer sk-mimo") ### Response #### Success Response (200) - **models** (array) - Description of the models available. ``` -------------------------------- ### Perform Streaming Chat via API Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Enable streaming for chat completions by setting the 'stream' parameter to true. The response will be in SSE format. ```bash curl http://localhost:8080/v1/chat/completions \ -H "Authorization: Bearer sk-mimo" \ -H "Content-Type: application/json" \ -d '{ "model": "mimo-v2-flash", "messages": [ {"role": "user", "content": "Tell me a story"} ], "stream": true }' ``` -------------------------------- ### Multimodal Image Upload via URL Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Send an image to the chat completions API using its URL. Requires omni/v2.5 models. ```bash curl http://localhost:8080/v1/chat/completions \ -H "Authorization: Bearer sk-mimo" \ -H "Content-Type: application/json" \ -d '{ "model": "mimo-v2-omni", "messages": [{"role": "user", "content": [{"type": "text", "text": "What is in this image?"},{"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}}]}] }' ``` -------------------------------- ### Multimodal Image Upload via Base64 Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Send an image to the chat completions API by encoding it as a Base64 string. Requires omni/v2.5 models. ```bash curl http://localhost:8080/v1/chat/completions \ -H "Authorization: Bearer sk-mimo" \ -H "Content-Type: application/json" \ -d '{ "model": "mimo-v2-omni", "messages": [{"role": "user", "content": [{"type": "text", "text": "Describe this image"},{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,/9j/4AAQ..."}}]}] }' ``` -------------------------------- ### Watch MiMo2API logs Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Displays real-time updates to the mimo.log file. ```bash # Watch real-time logs tail -f mimo.log ``` -------------------------------- ### Using the Responses API Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Interact with the chat completions endpoint using the newer Responses API format. Supports streaming, tool calling, and deep thinking. ```bash curl http://localhost:8080/v1/responses \ -H "Authorization: Bearer sk-mimo" \ -H "Content-Type: application/json" \ -d '{ "model": "mimo-v2-pro", "input": [ {"role": "user", "content": "Hello"} ] }' ``` -------------------------------- ### Multimodal Input - URL Method Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md This endpoint allows users to send images via URLs for multimodal analysis. It supports the chat completions API with image content types. ```APIDOC ## POST /v1/chat/completions (Multimodal - URL) ### Description Processes chat messages that include image content provided via a URL. This enables multimodal understanding of visual information within a conversational context. ### Method POST ### Endpoint /v1/chat/completions ### Parameters #### Request Body - **model** (string) - Required - The model to use for the completion (e.g., "mimo-v2-omni"). - **messages** (array) - Required - An array of message objects. Each object can contain: - **role** (string) - Required - The role of the message sender ('user' or 'assistant'). - **content** (array) - Required - An array of content blocks. Supported types include: - `{"type": "text", "text": "Your text prompt"}` - `{"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}}` ### Request Example ```json { "model": "mimo-v2-omni", "messages": [ { "role": "user", "content": [ {"type": "text", "text": "What is in this image?"}, {"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}} ] } ] } ``` ### Response #### Success Response (200) - **choices** (array) - Contains the model's response(s). - **message** (object) - The content of the message. - **content** (string) - The text response from the model. ``` -------------------------------- ### Clone MiMo2API No-Tools Version Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Clone the no-tools version of MiMo2API using Git. This version is recommended for use cases that do not require tool calling. ```bash git clone -b no-tools https://github.com/Fly143/MiMo2API.git ``` -------------------------------- ### Multimodal Input - Base64 Method Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md This endpoint allows users to send images encoded in Base64 format for multimodal analysis. It utilizes the chat completions API. ```APIDOC ## POST /v1/chat/completions (Multimodal - Base64) ### Description Processes chat messages that include image content provided as a Base64 encoded string. This enables multimodal understanding of visual information within a conversational context. ### Method POST ### Endpoint /v1/chat/completions ### Parameters #### Request Body - **model** (string) - Required - The model to use for the completion (e.g., "mimo-v2-omni"). - **messages** (array) - Required - An array of message objects. Each object can contain: - **role** (string) - Required - The role of the message sender ('user' or 'assistant'). - **content** (array) - Required - An array of content blocks. Supported types include: - `{"type": "text", "text": "Your text prompt"}` - `{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,/9j/4AAQ..."}}` (Base64 encoded image data) ### Request Example ```json { "model": "mimo-v2-omni", "messages": [ { "role": "user", "content": [ {"type": "text", "text": "Describe this image"}, {"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,/9j/4AAQ..."}} ] } ] } ``` ### Response #### Success Response (200) - **choices** (array) - Contains the model's response(s). - **message** (object) - The content of the message. - **content** (string) - The text response from the model. ``` -------------------------------- ### Perform Text Chat via API Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Send a POST request to the chat completions endpoint with model and message details for a standard text chat. ```bash curl http://localhost:8080/v1/chat/completions \ -H "Authorization: Bearer sk-mimo" \ -H "Content-Type: application/json" \ -d '{ "model": "mimo-v2-flash", "messages": [ {"role": "user", "content": "Hello, please reply in Chinese"} ] }' ``` -------------------------------- ### POST /v1/messages/batches Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Create a new batch task for processing multiple messages. ```APIDOC ## POST /v1/messages/batches ### Description Create a batch task to process multiple messages concurrently. ### Method POST ### Endpoint /v1/messages/batches ### Parameters #### Header Parameters - **x-api-key** (string) - Required - API key for authentication. - **Content-Type** (string) - Required - Must be `application/json`. #### Request Body - **tasks** (array) - Required - An array of task objects, each defining a message to process. ### Request Example ```json { "tasks": [ {"model": "mimo-v2-flash", "messages": [{"role": "user", "content": "Task 1"}]}, {"model": "mimo-v2-flash", "messages": [{"role": "user", "content": "Task 2"}]} ] } ``` ### Response #### Success Response (200) - **batch_id** (string) - The unique identifier for the created batch task. #### Response Example ```json { "batch_id": "batch_xyz789" } ``` ``` -------------------------------- ### Streaming Messages with cURL Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Send a message and receive a streaming response. Ensure the 'stream' parameter is set to true. ```bash curl -N -X POST http://localhost:8080/v1/messages \ -H "x-api-key: sk-mimo" \ -H "Content-Type: application/json" \ -H "anthropic-version: 2023-06-01" \ -d '{ "model": "mimo-v2-flash", "max_tokens": 1024, "stream": true, "messages": [ {"role": "user", "content": "Tell me a story"} ] }' ``` -------------------------------- ### Check MiMo2API process status Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Lists all running processes and filters for those related to 'python main.py'. ```bash # Check process status ps aux | grep "python main.py" ``` -------------------------------- ### POST /v1/responses (Streaming) Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md This endpoint handles streaming requests for generating responses using Server-Sent Events (SSE). It returns a stream of response chunks. ```APIDOC ## POST /v1/responses (Streaming) ### Description Handles streaming requests for generating responses using Server-Sent Events (SSE). It returns a stream of response chunks. ### Method POST ### Endpoint /v1/responses?stream=true ### Parameters #### Query Parameters - **stream** (boolean) - Required - Set to `true` to enable SSE streaming response chunks. #### Request Body - **model** (string) - Required - The model to use for generation. - **input** (array) - Required - An array of message objects, similar to OpenAI's `messages` field. - **role** (string) - Required - The role of the author of the message (e.g., "user", "system"). - **content** (string) - Required - The content of the message. - **instructions** (string) - Optional - System instructions for the model. - **tool_sieve** (boolean) - Optional - Enables the streaming sieve for tool calls. - **tools** (array) - Optional - Definitions of tools the model may use. - **name** (string) - Required - The name of the tool. - **tool_choice** (string or object) - Optional - Controls how the tool is chosen. ### Request Example ```json { "model": "mimo-v2-pro", "input": [{"role": "user", "content": "Tell me a story"}], "stream": true } ``` ### Response #### Success Response (200) - **data** (string) - Server-Sent Events stream containing response chunks. - Each chunk is a JSON object with `delta.content`, `delta.tool_calls`, or `tool_calls`. #### Response Example ``` data: {"delta": {"content": "Once upon a time"}} data: {"delta": {"content": ", in a land far, far away..."}} data: [DONE] ``` ``` -------------------------------- ### MiMo2API Response Format Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Illustrates the structure of a response from the MiMo2API, including reasoning, function calls, and messages. ```json { "output": [ { "type": "reasoning", "summary": [{"type": "summary_text", "text": "Model thinking..."}] }, { "type": "function_call", "id": "fc_abc123...", "call_id": "call_xyz789...", "name": "get_time", "arguments": "{}" }, { "type": "message", "role": "assistant", "status": "completed", "content": [{"type": "output_text", "text": "The current time is..."}] } ] } ``` -------------------------------- ### Docker Compose Configuration for MiMo2API Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Define MiMo2API service using docker-compose for containerized deployment, including volume mapping and restart policy. ```yaml services: mimo2api: image: ghcr.io/fly143/mimo2api:latest ports: - "8080:8080" volumes: - ./config.json:/app/config.json restart: unless-stopped ``` -------------------------------- ### Force Model List Refresh Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Manually trigger a refresh of the model list by sending a POST request to the `/v1/models/refresh` endpoint. ```bash # Force refresh model list curl -X POST http://localhost:8080/v1/models/refresh \ -H "Authorization: Bearer sk-mimo" ``` -------------------------------- ### File Upload for Text Analysis Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md This endpoint allows users to upload text files for analysis. The API reads the file content and responds based on it, supporting various plain text formats. ```APIDOC ## POST /v1/chat/completions (File Upload) ### Description Processes chat messages that include text file content. The API reads the file and uses its content to generate a response, suitable for tasks like summarization. ### Method POST ### Endpoint /v1/chat/completions ### Parameters #### Request Body - **model** (string) - Required - The model to use for the completion (e.g., "mimo-v2-pro"). - **messages** (array) - Required - An array of message objects. Each object can contain: - **role** (string) - Required - The role of the message sender ('user' or 'assistant'). - **content** (array) - Required - An array of content blocks. Supported types include: - `{"type": "text", "text": "Your text prompt"}` - `{"type": "file", "file": {"filename": "yourfile.md", "file_data": "BASE64_ENCODED_CONTENT"}}` ### Request Example ```json { "model": "mimo-v2-pro", "messages": [ { "role": "user", "content": [ {"type": "text", "text": "Summarize this file"}, {"type": "file", "file": {"filename": "yourfile.md", "file_data": "BASE64_ENCODED_CONTENT"}} ] } ] } ``` ### Response #### Success Response (200) - **choices** (array) - Contains the model's response(s). - **message** (object) - The content of the message. - **content** (string) - The text response from the model, based on the file content. ``` -------------------------------- ### Check MiMo2API port usage Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Lists network connections and filters for processes using port 8080. ```bash # Check port usage lsof -i :8080 ``` -------------------------------- ### Function Calling Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Enables the model to call external functions. The API defines tools, and the model can respond with function calls based on the user's request. ```APIDOC ## POST /v1/chat/completions (Function Calling) ### Description Allows the model to intelligently decide when and how to call external functions based on user queries. The API supports defining tools and their parameters, and the model can output structured function calls. ### Method POST ### Endpoint /v1/chat/completions ### Parameters #### Request Body - **model** (string) - Required - The model to use (e.g., "mimo-v2-pro"). - **messages** (array) - Required - An array of message objects representing the conversation history. - **tools** (array) - Optional - A list of tools the model may call. Each tool should have: - **type** (string) - Required - Type of the tool, e.g., "function". - **function** (object) - Required - Definition of the function: - **name** (string) - Required - Name of the function. - **description** (string) - Optional - Description of the function. - **parameters** (object) - Optional - JSON schema for the function's parameters. - **tool_choice** (string or object) - Optional - Controls how the tool is chosen. Can be "auto", "none", or a specific tool choice. ### Request Example ```json { "model": "mimo-v2-pro", "messages": [ {"role": "user", "content": "What is the weather in Beijing today?"} ], "tools": [ { "type": "function", "function": { "name": "get_weather", "description": "Query weather for a specified city", "parameters": { "type": "object", "properties": { "city": {"type": "string", "description": "City name"} }, "required": ["city"] } } } ], "tool_choice": "auto" } ``` ### Response #### Success Response (200) - **choices** (array) - Contains the model's response(s). - **finish_reason** (string) - Indicates why the model stopped generating, e.g., "tool_calls". - **message** (object) - The message object: - **role** (string) - "assistant". - **content** (string or null) - Null if `finish_reason` is "tool_calls". - **tool_calls** (array) - Contains information about the function calls to be made. - **id** (string) - Unique identifier for the tool call. - **type** (string) - Type of the tool call, e.g., "function". - **function** (object) - Details of the function call: - **name** (string) - The name of the function to call. - **arguments** (string) - JSON string representing the arguments for the function call. ``` -------------------------------- ### Streaming Chat Completions Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Sends a text-based chat message and receives a streaming response using Server-Sent Events (SSE). ```APIDOC ## Streaming Chat Completions ### Description Sends a text-based chat message and receives a streaming response using Server-Sent Events (SSE). ### Method POST ### Endpoint /v1/chat/completions ### Parameters #### Headers - **Authorization** (string) - Required - Bearer token (e.g., "Bearer sk-mimo") - **Content-Type** (string) - Required - application/json #### Request Body - **model** (string) - Required - The model to use for the chat completion (e.g., "mimo-v2-flash") - **messages** (array) - Required - An array of message objects, where each object has a `role` (user/assistant/system) and `content`. - **stream** (boolean) - Optional - Set to `true` to enable streaming. ### Request Example ```json { "model": "mimo-v2-flash", "messages": [ {"role": "user", "content": "Tell me a story"} ], "stream": true } ``` ### Response Returns standard SSE stream (`data: ...\n\n`), ending with `data: [DONE]\n\n`. ``` -------------------------------- ### Stop MiMo2API by process name Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Stops the MiMo2API service by killing processes matching 'python main.py'. ```bash # Stop by process name pkill -f "python main.py" ``` -------------------------------- ### POST /v1/messages Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Send a message to the API. This endpoint supports both streaming and non-streaming responses, and can include thinking processes. ```APIDOC ## POST /v1/messages ### Description Send a message to the API for processing. Supports streaming responses and can include thinking steps. ### Method POST ### Endpoint /v1/messages ### Parameters #### Header Parameters - **x-api-key** (string) - Required - API key for authentication. - **Content-Type** (string) - Required - Must be `application/json`. - **anthropic-version** (string) - Required - API version, e.g., `2023-06-01`. #### Request Body - **model** (string) - Required - The model to use for generation (e.g., `mimo-v2-flash`). - **max_tokens** (integer) - Required - The maximum number of tokens to generate. - **stream** (boolean) - Optional - Whether to stream the response. - **messages** (array) - Required - An array of message objects, each with `role` (string) and `content` (string). - **tools** (array) - Optional - An array of tool definitions for the model to use. ### Request Example ```json { "model": "mimo-v2-flash", "max_tokens": 1024, "stream": true, "messages": [ {"role": "user", "content": "Tell me a story"} ] } ``` ### Response #### Success Response (200) - **content** (array) - The response content from the model. - **stop_reason** (string) - The reason the response stopped (e.g., `end_turn`, `max_tokens`, `tool_use`). #### Response Example ```json { "content": [ {"type": "text", "text": "Once upon a time..."} ], "stop_reason": "end_turn" } ``` ``` -------------------------------- ### Responses API Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Provides an alternative API format compatible with OpenAI's latest Responses API, supporting features like streaming and tool calling. ```APIDOC ## POST /v1/responses ### Description An endpoint that adheres to OpenAI's Responses API format. It supports various features including streaming responses, function/tool calling, and deep thinking. ### Method POST ### Endpoint /v1/responses ### Parameters #### Request Body - **model** (string) - Required - The model to use for the response generation (e.g., "mimo-v2-pro"). - **input** (array) - Required - An array of message objects, similar to the chat completions API, defining the conversation input. - **stream** (boolean) - Optional - If `true`, responses will be streamed. - **tools** (array) - Optional - Definitions for tools the model can use. - **reasoning_effort** (string) - Optional - Controls the depth of reasoning (e.g., "high"). ### Request Example ```json { "model": "mimo-v2-pro", "input": [ {"role": "user", "content": "Hello"} ] } ``` ### Response #### Success Response (200) - **choices** (array) - Contains the model's response(s). - **message** (object) - The content of the message. - **content** (string) - The text response from the model. If streaming, this may be part of a streamed chunk. ``` -------------------------------- ### POST /v1/responses (Non-streaming) Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md This endpoint handles non-streaming requests for generating responses. It accepts a model name and input messages, returning a single response object. ```APIDOC ## POST /v1/responses ### Description Handles non-streaming requests for generating responses. It accepts a model name and input messages, returning a single response object. ### Method POST ### Endpoint /v1/responses ### Parameters #### Query Parameters - **stream** (boolean) - Optional - If set to true, streams SSE response chunks #### Request Body - **model** (string) - Required - The model to use for generation. - **input** (array) - Required - An array of message objects, similar to OpenAI's `messages` field. - **role** (string) - Required - The role of the author of the message (e.g., "user", "system"). - **content** (string) - Required - The content of the message. - **instructions** (string) - Optional - System instructions for the model. - **tool_sieve** (boolean) - Optional - Enables the streaming sieve for tool calls. - **tools** (array) - Optional - Definitions of tools the model may use. - **name** (string) - Required - The name of the tool. - **tool_choice** (string or object) - Optional - Controls how the tool is chosen. ### Request Example ```json { "model": "mimo-v2-pro", "input": [{"role": "user", "content": "Hello"}] } ``` ### Response #### Success Response (200) - **output** (array) - An array of output objects, representing the model's response. - **type** (string) - The type of output (e.g., "content", "function_call", "reasoning"). - **content** (string) - The text content of the response (if type is "content"). - **name** (string) - The name of the tool function to call (if type is "function_call"). - **arguments** (string) - The arguments to pass to the tool function (if type is "function_call"). #### Response Example ```json { "output": [ { "type": "content", "content": "Hi there! How can I help you today?" } ] } ``` ``` -------------------------------- ### Model Refresh Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Forces the API to refresh its list of available models by fetching the latest configuration. ```APIDOC ## POST /v1/models/refresh ### Description Initiates a refresh of the available models list. This action fetches the latest model configurations from the discovery endpoint, ensuring the API is aware of all current models. ### Method POST ### Endpoint /v1/models/refresh ### Parameters No specific parameters are required for this endpoint. ### Response #### Success Response (200) Indicates that the model list refresh was initiated successfully. The API will update its internal model registry. ``` -------------------------------- ### POST /v1/messages/count_tokens Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Estimate the token count for a given message, useful for managing costs and input limits. ```APIDOC ## POST /v1/messages/count_tokens ### Description Estimate the number of tokens for a given message. This is a local estimation and requires the `tiktoken` library. ### Method POST ### Endpoint /v1/messages/count_tokens ### Parameters #### Header Parameters - **x-api-key** (string) - Required - API key for authentication. - **Content-Type** (string) - Required - Must be `application/json`. #### Request Body - **model** (string) - Required - The model for which to count tokens. - **messages** (array) - Required - An array of message objects. ### Request Example ```json { "model": "mimo-v2-flash", "messages": [ {"role": "user", "content": "Count these tokens"} ] } ``` ### Response #### Success Response (200) - **total_tokens** (integer) - The estimated total number of tokens. #### Response Example ```json { "total_tokens": 15 } ``` ``` -------------------------------- ### Deep Thinking with High Reasoning Effort Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Enable deep thinking for complex reasoning tasks by setting the `reasoning_effort` parameter to 'high'. Supports streaming responses. ```bash curl http://localhost:8080/v1/chat/completions \ -H "Authorization: Bearer sk-mimo" \ -H "Content-Type: application/json" \ -d '{ "model": "mimo-v2-pro", "messages": [ {"role": "user", "content": "Prove that sqrt(2) is irrational"} ], "reasoning_effort": "high", "stream": true }' ``` -------------------------------- ### Stop MiMo2API using PID file Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Stops the MiMo2API service by reading its process ID from the mimo.pid file. ```bash # Stop from PID file kill $(cat mimo.pid) ``` -------------------------------- ### Text Chat Completions Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Sends a text-based chat message and receives a non-streaming response. ```APIDOC ## Text Chat Completions ### Description Sends a text-based chat message and receives a non-streaming response. ### Method POST ### Endpoint /v1/chat/completions ### Parameters #### Headers - **Authorization** (string) - Required - Bearer token (e.g., "Bearer sk-mimo") - **Content-Type** (string) - Required - application/json #### Request Body - **model** (string) - Required - The model to use for the chat completion (e.g., "mimo-v2-flash") - **messages** (array) - Required - An array of message objects, where each object has a `role` (user/assistant/system) and `content`. ### Request Example ```json { "model": "mimo-v2-flash", "messages": [ {"role": "user", "content": "Hello, please reply in Chinese"} ] } ``` ### Response #### Success Response (200) - **choices** (array) - Contains the model's response. - **message** (object) - Contains the role and content of the response. ``` -------------------------------- ### POST /v1/messages/batches/{batch_id}/cancel Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Cancel a running batch task. ```APIDOC ## POST /v1/messages/batches/{batch_id}/cancel ### Description Cancel a batch task that is currently in progress. ### Method POST ### Endpoint /v1/messages/batches/{batch_id}/cancel ### Parameters #### Path Parameters - **batch_id** (string) - Required - The unique identifier of the batch task to cancel. #### Header Parameters - **x-api-key** (string) - Required - API key for authentication. ### Response #### Success Response (200) - **message** (string) - Confirmation message indicating the batch was cancelled. #### Response Example ```json { "message": "Batch batch_xyz789 cancelled successfully." } ``` ``` -------------------------------- ### Anthropic Messages API Source: https://github.com/fly143/mimo2api/blob/main/README_EN.md Provides full compatibility with the Anthropic Messages API, allowing users to interact with MiMo2API using Anthropic's message format. ```APIDOC ## POST /v1/messages (Anthropic Messages API) ### Description This endpoint implements the Anthropic Messages API format, enabling seamless integration for applications already using Anthropic's messaging interface. It supports non-streaming and streaming responses. ### Method POST ### Endpoint /v1/messages ### Headers - **x-api-key** (string) - Required - Your API key (e.g., "sk-mimo"). - **Content-Type** (string) - Required - Must be "application/json". - **anthropic-version** (string) - Required - The API version, e.g., "2023-06-01". ### Parameters #### Request Body - **model** (string) - Required - The model to use (e.g., "mimo-v2-flash"). - **max_tokens** (integer) - Required - The maximum number of tokens to generate. - **messages** (array) - Required - An array of message objects, following Anthropic's format: - **role** (string) - Required - Role of the message sender ('user' or 'assistant'). - **content** (string or array) - Required - The content of the message. ### Request Example ```json { "model": "mimo-v2-flash", "max_tokens": 1024, "messages": [ {"role": "user", "content": "Hello"} ] } ``` ### Response #### Success Response (200) - **content** (array) - The content of the assistant's message. - **role** (string) - The role of the message sender ('assistant'). - **stop_reason** (string) - The reason the model stopped generating tokens. ```