Skip to content

Latest commit

 

History

History
168 lines (138 loc) · 3.63 KB

File metadata and controls

168 lines (138 loc) · 3.63 KB

API Guide

This document introduces how to use the APIs for MiniCPM-V 4.6 and MiniCPM-o 4.5.

MiniCPM-V 4.6

MiniCPM-V 4.6 can be called through the Chat Completions API. The interface supports both text-only and vision-language requests.

Endpoint

Base URL: https://api.modelbest.cn/v1
Chat API: POST /chat/completions
Authorization: Bearer <API_KEY>
Content-Type: application/json

A free public API key is currently available for trying the service:

sk-pQ8L2zF3XmR5kY9wV4jB7hN1tC6vM0xG3aD5sH2bJ9lK4cZ8

Available model IDs:

MiniCPM-V-4.6-Instruct
MiniCPM-V-4.6-Thinking

Text-Only Request

curl https://api.modelbest.cn/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MiniCPM-V-4.6-Instruct",
    "messages": [
      {
        "role": "user",
        "content": "Introduce yourself in one sentence."
      }
    ]
  }'

To use the Thinking model, replace the model value with:

"MiniCPM-V-4.6-Thinking"

Vision-Language Request

Images are passed as base64 data URLs in the image_url content format.

curl https://api.modelbest.cn/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MiniCPM-V-4.6-Instruct",
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "Describe this image."
          },
          {
            "type": "image_url",
            "image_url": {
              "url": "data:image/png;base64,<BASE64_IMAGE>"
            }
          }
        ]
      }
    ]
  }'

Python Example

import json
import urllib.request

api_key = "<API_KEY>"
payload = {
    "model": "MiniCPM-V-4.6-Instruct",
    "messages": [
        {
            "role": "user",
            "content": "List three use cases for MiniCPM-V.",
        }
    ],
}

request = urllib.request.Request(
    "https://api.modelbest.cn/v1/chat/completions",
    data=json.dumps(payload).encode("utf-8"),
    headers={
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json",
    },
    method="POST",
)

with urllib.request.urlopen(request) as response:
    data = json.loads(response.read().decode("utf-8"))

print(data["choices"][0]["message"]["content"])

MiniCPM-o 4.5

MiniCPM-o 4.5 can be called through the Chat Completions API for both traditional text and vision-language requests, and also full-duplex realtime interaction.

Text-Only Request

curl https://api.modelbest.cn/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MiniCPM-o-4.5",
    "messages": [
      {
        "role": "user",
        "content": "Introduce yourself in one sentence."
      }
    ]
  }'

Vision-Language Request

curl https://api.modelbest.cn/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MiniCPM-o-4.5",
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "Describe this image."
          },
          {
            "type": "image_url",
            "image_url": {
              "url": "data:image/png;base64,<BASE64_IMAGE>"
            }
          }
        ]
      }
    ]
  }'

Realtime API

MiniCPM-o 4.5 also supports full-duplex realtime multimodal interaction. For the Realtime API documentation, see the Realtime API Overview.