すべてのプロダクト
Search
ドキュメントセンター

Alibaba Cloud Model Studio:Kimi

最終更新日:Sep 09, 2026

このドキュメントでは、Alibaba Cloud Model Studio にデプロイされた Kimi モデルの推論サービスを呼び出す方法について説明します。

重要Moonshot-Kimi-K2-Instruct および kimi-k2-thinking は 2026 年 7 月 9 日に廃止されます。qwen3.7-plus、qwen3.8-max、または qwen3.8-flash への移行を推奨します。

サポートされているリージョン: 中国 (北京)、シンガポール、日本 (東京)、中国 (香港)、ドイツ (フランクフルト)、および米国 (バージニア)。

モデル体験: モデル体験センターで Kimi モデルを試すことができます。

サービスエンドポイントはリージョン固有です。ご利用のリージョンに合わせて正しいベース URL を設定してください。

OpenAI 互換

米国 (バージニア)

SDK 呼び出しの base_url は次のとおりです: https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/compatible-mode/v1

HTTP リクエスト URL: POST https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions

ドイツ (フランクフルト)

SDK 呼び出しの base_url は次のとおりです: https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/compatible-mode/v1

HTTP リクエスト URL: POST https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions

シンガポール

SDK 呼び出しの base_url は次のとおりです: https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1

HTTP リクエスト URL: POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions

日本 (東京)

SDK 呼び出しの base_url は次のとおりです: https://{WorkspaceId}.ap-northeast-1.maas.aliyuncs.com/compatible-mode/v1

HTTP リクエスト URL: POST https://{WorkspaceId}.ap-northeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions

中国 (北京)

SDK 呼び出しの base_url は次のとおりです: https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1

HTTP リクエスト URL: POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions

中国 (香港)

SDK 呼び出しの base_url は次のとおりです: https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/compatible-mode/v1

HTTP リクエスト URL: POST https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/compatible-mode/v1/chat/completions

DashScope

米国 (バージニア)

kimi-k2-thinking などのテキストモデルの HTTP リクエスト URL は POST https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation です。

kimi-k2.6 や kimi-k2.5 などのマルチモーダルモデルの HTTP リクエスト URL は POST https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation です。

SDK 呼び出しの base_url は次のとおりです:

Python コード

dashscope.base_http_api_url = 'https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1'

Java コード

  • 方法 1:
import com.alibaba.dashscope.protocol.Protocol;
Generation gen = new Generation(Protocol.HTTP.getValue(), "https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1");
  • 方法 2:
import com.alibaba.dashscope.utils.Constants;
Constants.baseHttpApiUrl="https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1";

ドイツ (フランクフルト)

kimi-k2-thinking などのテキストモデルの HTTP リクエスト URL は POST https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation です。

kimi-k2.7-code、kimi-k2.6、kimi-k2.5 などのマルチモーダルモデルの HTTP リクエスト URL は POST https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation です。

SDK 呼び出しの base_url は次のとおりです:

Python コード

dashscope.base_http_api_url = 'https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1'

Java コード

  • 方法 1:
import com.alibaba.dashscope.protocol.Protocol;
Generation gen = new Generation(Protocol.HTTP.getValue(), "https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1");
  • 方法 2:
import com.alibaba.dashscope.utils.Constants;
Constants.baseHttpApiUrl="https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1";

シンガポール

kimi-k2-thinking などのテキストモデルの HTTP リクエスト URL は POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation です。

kimi-k2.7-code、kimi-k2.6、kimi-k2.5 などのマルチモーダルモデルの HTTP リクエスト URL は POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation です。

SDK 呼び出しの base_url は次のとおりです:

Python コード

# シンガポールリージョン。{WorkspaceId} をご利用の Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'

Java コード

  • オプション 1:
import com.alibaba.dashscope.protocol.Protocol;
// シンガポールリージョン。{WorkspaceId} をご利用の Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
Generation gen = new Generation(Protocol.HTTP.getValue(), "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1");
  • オプション 2:
import com.alibaba.dashscope.utils.Constants;
// シンガポールリージョン。{WorkspaceId} をご利用の Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
Constants.baseHttpApiUrl="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";

日本 (東京)

kimi-k2-thinking などのテキストモデルの HTTP リクエスト URL は POST https://{WorkspaceId}.ap-northeast-1.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation です。

kimi-k2.7-code、kimi-k2.6、kimi-k2.5 などのマルチモーダルモデルの HTTP リクエスト URL は POST https://{WorkspaceId}.ap-northeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation です。

SDK 呼び出しの base_url は次のとおりです:

Python コード

dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-northeast-1.maas.aliyuncs.com/api/v1'

Java コード

  • オプション 1:
import com.alibaba.dashscope.protocol.Protocol;
Generation gen = new Generation(Protocol.HTTP.getValue(), "https://{WorkspaceId}.ap-northeast-1.maas.aliyuncs.com/api/v1");
  • オプション 2:
import com.alibaba.dashscope.utils.Constants;
Constants.baseHttpApiUrl="https://{WorkspaceId}.ap-northeast-1.maas.aliyuncs.com/api/v1";

中国 (香港)

kimi-k2-thinking などのテキストモデルの HTTP リクエスト URL は POST https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation です。

kimi-k2.7-code、kimi-k2.6、kimi-k2.5 などのマルチモーダルモデルの HTTP リクエスト URL は POST https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation です。

SDK 呼び出しの base_url は次のとおりです:

Python コード

dashscope.base_http_api_url = 'https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/api/v1'

Java コード

  • 方法 1:
import com.alibaba.dashscope.protocol.Protocol;
Generation gen = new Generation(Protocol.HTTP.getValue(), "https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/api/v1");
  • 方法 2:
import com.alibaba.dashscope.utils.Constants;
Constants.baseHttpApiUrl="https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/api/v1";

中国 (北京)

kimi-k2-thinking などのテキストモデルの HTTP リクエスト URL は POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation です。

kimi-k2.7-code、kimi-k2.6、kimi-k2.5 などのマルチモーダルモデルの HTTP リクエスト URL は POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation です。

SDK 呼び出しの base_url は次のとおりです:

Python コード

# 中国 (北京) リージョン。{WorkspaceId} をご利用の Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
dashscope.base_http_api_url = 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1'

Java コード

  • オプション 1:
import com.alibaba.dashscope.protocol.Protocol;
// 中国 (北京) リージョン。{WorkspaceId} をご利用の Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
Generation gen = new Generation(Protocol.HTTP.getValue(), "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1");
  • オプション 2:
import com.alibaba.dashscope.utils.Constants;
// 中国 (北京) リージョン。{WorkspaceId} をご利用の Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
Constants.baseHttpApiUrl="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1";

{WorkspaceId} を実際の ワークスペース ID に置き換えます。

前提条件: API キーを取得し、環境変数として設定する必要があります。SDK を使用する場合は、SDK をインストールする必要があります。

クイックスタート

以下の例では、テキストのみの入力を使用します。マルチモーダルの例については、「マルチモーダル呼び出し」をご参照ください。

OpenAI 互換

Python

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 中国 (北京) リージョン。{WorkspaceId} をお使いの Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)

completion = client.chat.completions.create(
    model="kimi-k2.6",
    messages=[{"role": "user", "content": "Who are you?"}],
    stream=True,
    extra_body={"enable_thinking": True},  # 思考モードを有効にして reasoning_content を取得します
)

reasoning_content = ""  # 完全な思考プロセス
answer_content = ""     # 完全な応答
is_answering = False    # メインの応答が開始されたかどうかを追跡します。

print("\n" + "=" * 20 + "Thinking Process" + "=" * 20 + "\n")

for chunk in completion:
    if chunk.choices:
        delta = chunk.choices[0].delta
        # 思考プロセスのコンテンツを保存します。
        if hasattr(delta, "reasoning_content") and delta.reasoning_content is not None:
            if not is_answering:
                print(delta.reasoning_content, end="", flush=True)
            reasoning_content += delta.reasoning_content
        # メインの応答のコンテンツが到着したら、その出力を開始します。
        if hasattr(delta, "content") and delta.content:
            if not is_answering:
                print("\n" + "=" * 20 + "Complete Response" + "=" * 20 + "\n")
                is_answering = True
            print(delta.content, end="", flush=True)
            answer_content += delta.content

応答

====================思考プロセス====================

ユーザーは「あなたは誰ですか?」と質問しています。これは私の ID に関する直接的な質問です。実際の ID に基づいて忠実に回答する必要があります。

私は Moonshot AI によって開発された AI アシスタント、Kimi です。自己紹介は明確かつ簡潔に行うべきです。含めるべき内容は以下の通りです:
1. 私の ID:AI アシスタント
2. 私の開発者:Moonshot AI
3. 私の名前:Kimi
4. 私のコア機能:長文テキスト処理、インテリジェントな会話、ファイル処理、検索など。

明確さを保つため、専門用語の使いすぎを避け、フレンドリでプロフェッショナルなトーンを維持すべきです。また、誤解を避けるために、私が個人的な意識、感情、経験を持たない AI であることを強調すべきです。

応答の構造:
- 直接的に私の ID を述べる
- 私の開発者に言及する
- コア機能を簡潔に紹介する
- 明確かつ簡潔に保つ
====================完全な応答====================

私は Moonshot AI によって開発された AI アシスタント、Kimi です。私は Mixture-of-Experts (MoE) アーキテクチャに基づいており、超長文コンテキスト理解、インテリジェントな会話、ファイル処理、コード生成、複雑なタスクの推論などの能力を持っています。何かお手伝いできることはありますか?

Node.js

import OpenAI from "openai";
import process from 'process';

// OpenAI クライアントを初期化します
const openai = new OpenAI({
    // 環境変数を使用しない場合は、`process.env.DASHSCOPE_API_KEY` をお使いの API キー文字列 (例: "sk-xxx") に置き換えてください。
    apiKey: process.env.DASHSCOPE_API_KEY,
    // 中国 (北京) リージョン。{WorkspaceId} をお使いの Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    baseURL: 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1'
});

let reasoningContent = ''; // 完全な思考プロセス
let answerContent = ''; // 完全な応答
let isAnswering = false; // メインの応答が開始されたかどうかを追跡します。

async function main() {
    const messages = [{ role: 'user', content: 'Who are you?' }];

    const stream = await openai.chat.completions.create({
        model: 'kimi-k2.6',
        messages,
        stream: true,
        enable_thinking: true,  // 思考モードを有効にして reasoning_content を取得します
    });

    console.log('\n' + '='.repeat(20) + 'Thinking Process' + '='.repeat(20) + '\n');

    for await (const chunk of stream) {
        if (chunk.choices?.length) {
            const delta = chunk.choices[0].delta;
            // 思考プロセスのコンテンツを保存します。
            if (delta.reasoning_content !== undefined && delta.reasoning_content !== null) {
                if (!isAnswering) {
                    process.stdout.write(delta.reasoning_content);
                }
                reasoningContent += delta.reasoning_content;
            }

            // メインの応答のコンテンツが到着したら、その出力を開始します。
            if (delta.content !== undefined && delta.content) {
                if (!isAnswering) {
                    console.log('\n' + '='.repeat(20) + 'Complete Response' + '='.repeat(20) + '\n');
                    isAnswering = true;
                }
                process.stdout.write(delta.content);
                answerContent += delta.content;
            }
        }
    }
}

main();

応答

====================思考プロセス====================

ユーザーは「あなたは誰ですか?」と質問しています。これは私の ID に関する直接的な質問です。実際の ID に基づいて忠実に回答する必要があります。

私は Moonshot AI によって開発された AI アシスタント、Kimi です。自己紹介は明確かつ簡潔に行うべきです。含めるべき内容は以下の通りです:
1. 私の ID:AI アシスタント
2. 私の開発者:Moonshot AI
3. 私の名前:Kimi
4. 私のコア機能:長文テキスト処理、インテリジェントな会話、ファイル処理、検索など。

明確さを保つため、専門用語の使いすぎを避け、フレンドリでプロフェッショナルなトーンを維持すべきです。また、誤解を避けるために、私が個人的な意識、感情、経験を持たない AI であることを強調すべきです。

応答の構造:
- 直接的に私の ID を述べる
- 私の開発者に言及する
- コア機能を簡潔に紹介する
- 明確かつ簡潔に保つ
====================完全な応答====================

私は Moonshot AI によって開発された AI アシスタント、Kimi です。

私の得意なことは以下の通りです:
- 長文テキストの理解と生成
- インテリジェントな会話と質疑応答
- ファイルの処理と分析
- 情報の取得と統合

AI アシスタントとして、私には個人的な意識、感情、経験はありませんが、正確で役立つ支援を提供するように設計されています。何かお手伝いできることはありますか?

HTTP

curl

# 中国 (北京) リージョン。{WorkspaceId} をお使いの Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
curl -X POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "kimi-k2.6",
    "messages": [
        {
            "role": "user",
            "content": "Who are you?"
        }
    ],
    "enable_thinking": true
}'

応答

{
    "choices": [
        {
            "message": {
                "content": "私は Moonshot AI によって開発された AI アシスタント、Kimi です。長文テキスト処理、インテリジェントな会話、ファイル分析、プログラミング支援、複雑なタスクの推論が得意です。質問への回答、コンテンツ作成、ドキュメント分析などをお手伝いできます。何かお手伝いできることはありますか?",
                "reasoning_content": "ユーザーは「あなたは誰ですか?」と質問しています。これは私の ID に関する直接的な質問です。実際の ID に基づいて忠実に回答する必要があります。\n\n私は Moonshot AI によって開発された AI アシスタント、Kimi です。自己紹介は明確かつ簡潔に行うべきです。含めるべき内容は以下の通りです:\n1. 私の ID:AI アシスタント\n2. 私の開発者:Moonshot AI\n3. 私の名前:Kimi\n4. 私のコア機能:長文テキスト処理、インテリジェントな会話、ファイル処理、検索など。\n\n役立つ情報を提供しつつ、フレンドリでプロフェッショナルなトーンを維持すべきです。複雑にしすぎる必要はなく、直接的な回答で十分です。",
                "role": "assistant"
            },
            "finish_reason": "stop",
            "index": 0,
            "logprobs": null
        }
    ],
    "object": "chat.completion",
    "usage": {
        "prompt_tokens": 8,
        "completion_tokens": 183,
        "total_tokens": 191
    },
    "created": 1762753998,
    "system_fingerprint": null,
    "model": "kimi-k2.6",
    "id": "chatcmpl-485ab490-90ec-48c3-85fa-1c732b683db2"
}

DashScope

以下の DashScope の例では、multimodal-generation エンドポイントを使用して kimi-k2.6 を呼び出します。これはテキストとマルチモーダルの両方の入力をサポートします。その他のマルチモーダルの例については、「マルチモーダル呼び出し」をご参照ください。

Python

import os
import dashscope
from dashscope import MultiModalConversation
# 中国 (北京) リージョンの構成。{WorkspaceId} を実際のワークスペース ID に置き換えてください。他のリージョンについては、対応するベース URL を使用してください。
dashscope.base_http_api_url = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1"

# リクエストメッセージを定義します。
messages = [{"role": "user", "content": "Who are you?"}]

completion = MultiModalConversation.call(
    api_key=os.getenv("DASHSCOPE_API_KEY"),  # 環境変数を使用しない場合は、キーを直接指定します。例:api_key="sk-xxx"
    model="kimi-k2.6",
    messages=messages,
    result_format="message",  # 結果のフォーマットを message に設定します
    stream=True,              # ストリーミングを有効にします。
    incremental_output=True,  # 増分出力を有効にします
    enable_thinking=True,     # 思考モードを有効にして reasoning_content を取得します
)

reasoning_content = ""  # 完全な思考プロセス
answer_content = ""     # 完全な応答
is_answering = False    # メインの応答が開始されたかどうかを追跡します。

print("\n" + "=" * 20 + "Thinking Process" + "=" * 20 + "\n")

for chunk in completion:
    message = chunk.output.choices[0].message

    # 思考プロセスのコンテンツを保存します。
    reasoning_chunk = message.get("reasoning_content")
    if reasoning_chunk:
        if not is_answering:
            print(reasoning_chunk, end="", flush=True)
        reasoning_content += reasoning_chunk

    # メインの応答のコンテンツが到着したら、その出力を開始します。content はリストなので、そこからテキストを抽出します。
    if message.get("content"):
        text = message.content[0].get("text", "")
        if not is_answering:
            print("\n" + "=" * 20 + "Complete Response" + "=" * 20 + "\n")
            is_answering = True
        print(text, end="", flush=True)
        answer_content += text

応答

====================思考プロセス====================

ユーザーは「あなたは誰ですか?」と質問しています。これは私の ID に関する直接的な質問です。実際の ID に基づいて忠実に回答する必要があります。

私は Moonshot AI によって開発された AI アシスタント、Kimi です。このことを明確かつ簡潔に述べるべきです。

含めるべき重要な情報:
1. 私の名前:Kimi
2. 私の開発者:Moonshot AI
3. 私の性質:AI アシスタント
4. 私にできること:質問への回答、コンテンツ作成の支援など。

私の ID を正確に述べながら、フレンドリで役立つトーンを維持すべきです。人間であるかのように振る舞ったり、個人的な ID を持っているかのように見せかけたりしてはいけません。

適切な応答は次のようになります:
「私は Moonshot AI によって開発された AI アシスタント、Kimi です。質問への回答、コンテンツ作成、ドキュメント分析など、さまざまなタスクをお手伝いできます。何かお手伝いできることはありますか?」

この応答は直接的で正確であり、さらなる対話を促します。
====================完全な応答====================

私は Moonshot AI によって開発された AI アシスタント、Kimi です。質問への回答、コンテンツ作成、ドキュメント分析など、さまざまなタスクをお手伝いできます。何かお手伝いできることはありますか?

Java

// DashScope SDK バージョン >= 2.19.4
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.common.MultiModalMessage;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.Constants;
import java.util.Arrays;
import java.util.Collections;

public class Main {
    public static void main(String[] args) {
        // 中国 (北京) リージョンの構成。{WorkspaceId} を実際のワークスペース ID に置き換えてください。他のリージョンについては、対応するベース URL を使用してください。
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1";
        try {
            MultiModalConversation conv = new MultiModalConversation();

            MultiModalMessage userMsg = MultiModalMessage.builder()
                    .role(Role.USER.getValue())
                    .content(Arrays.asList(Collections.singletonMap("text", "Who are you?")))
                    .build();

            MultiModalConversationParam param = MultiModalConversationParam.builder()
                    // 環境変数を使用しない場合は、次の行をお使いの API キーに置き換えてください。例:.apiKey("sk-xxx")
                    .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                    .model("kimi-k2.6")
                    .messages(Arrays.asList(userMsg))
                    .build();

            MultiModalConversationResult result = conv.call(param);

            String content = (String) result.getOutput().getChoices().get(0).getMessage().getContent().get(0).get("text");
            System.out.println("Response: " + content);
        } catch (ApiException | NoApiKeyException | UploadFileException e) {
            System.err.println("An exception occurred: " + e.getMessage());
        }
        System.exit(0);
    }
}

応答

====================思考プロセス====================
ユーザーは「あなたは誰ですか?」と質問しています。これは私の ID に関する直接的な質問です。実際の ID に基づいて忠実に回答する必要があります。

私は Moonshot AI によって開発された AI アシスタント、Kimi です。このことを明確かつ簡潔に述べるべきです。

応答に含めるべき内容:
1. 私の ID:AI アシスタント
2. 私の開発者:Moonshot AI
3. 私の名前:Kimi
4. 私のコア機能:長文テキスト処理、インテリジェントな会話、ファイル処理など。

人間であるかのように振る舞ったり、過度に技術的な詳細を提供したりすべきではありません。明確でフレンドリな回答で十分です。
====================完全な応答====================
私は Moonshot AI によって開発された AI アシスタント、Kimi です。私のスキルには、長文テキスト処理、インテリジェントな会話、質疑応答、コンテンツ作成、ファイル分析と処理が含まれます。何かお手伝いできることはありますか?

HTTP

curl

# 中国 (北京) リージョン。{WorkspaceId} をお使いの Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
curl -X POST "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "kimi-k2.6",
    "input":{
        "messages":[
            {
                "role": "user",
                "content": "Who are you?"
            }
        ]
    },
    "parameters": {
        "result_format": "message",
        "enable_thinking": true
    }
}'

応答

{
    "output": {
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "content": "私は Moonshot AI によって開発された AI アシスタント、Kimi です。質問への回答、コンテンツ作成、ドキュメント分析、コード作成などをお手伝いできます。何かお手伝いできることはありますか?",
                    "reasoning_content": "ユーザーは「あなたは誰ですか?」と質問しています。これは私の ID に関する直接的な質問です。実際の ID に基づいて忠実に回答する必要があります。\n\n私は Moonshot AI によって開発された AI アシスタント、Kimi です。このことを明確かつ簡潔に述べるべきです。\n\n含めるべき重要な情報:\n1. 私の名前:Kimi\n2. 私の開発者:Moonshot AI\n3. 私の性質:AI アシスタント\n4. 私にできること:質問への回答、コンテンツ作成の支援など。\n\n応答はフレンドリで、直接的で、理解しやすいものであるべきです。",
                    "role": "assistant"
                }
            }
        ]
    },
    "usage": {
        "input_tokens": 9,
        "output_tokens": 156,
        "total_tokens": 165
    },
    "request_id": "709a0697-ed1f-4298-82c9-a4b878da1849"
}

Anthropic 互換

Python

サンプルコード

import anthropic
import os

client = anthropic.Anthropic(
    # 環境変数が設定されていない場合は、この値をお使いの Model Studio API キーに置き換えてください: api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 呼び出しを行う際に、{WorkspaceId} を実際のワークスペース ID に置き換えてください。
    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
)

message = client.messages.create(
    model="kimi-k2.6",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Who are you?"}
    ],
    stream=True,
)

for event in message:
    if event.type == "content_block_delta":
        if hasattr(event.delta, "thinking"):
            print(event.delta.thinking, end="", flush=True)
        if hasattr(event.delta, "text"):
            print(event.delta.text, end="", flush=True)

HTTP

サンプルコード

curl

# シンガポールリージョン。{WorkspaceId} をお使いの Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
curl -X POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic/v1/messages \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-H "anthropic-version: 2023-06-01" \
-d '{
    "model": "kimi-k2.6",
    "max_tokens": 1024,
    "messages": [
        {
            "role": "user",
            "content": "Who are you?"
        }
    ]
}'

マルチモーダル呼び出し

kimi-k2.7-code、kimi-k2.6、および kimi-k2.5 モデルは、テキスト、イメージ、またはビデオを同時に処理できます。enable_thinking パラメーターを使用して、思考モードを有効にします。以下の例では、この機能の使用方法を示します。

思考モードの有効化または無効化

kimi-k2.6 と kimi-k2.5 はハイブリッド思考モデルです。これらのモデルは、思考してから返信するか、直接返信することができます。enable_thinking パラメーターを使用して、思考モードを有効にするかどうかをコントロールできます:

  • true:思考モードを有効にします
  • false (デフォルト):思考モードを無効にします

kimi-k2.7-code は思考専用モデルです。思考モードは常に有効であり (enable_thinking はデフォルトで true となり無効化できません)、preserve_thinking もデフォルトで true となります。

kimi-k2.6 では、preserve_thinking パラメーターを使用することで、マルチターン対話で思考プロセスを渡すことができます。 詳細については、「思考プロセスを渡す」をご参照ください。

以下の例では、画像 URL の使用方法と思考モードの有効化について説明します。主な例では単一画像入力を、コメントアウトされたコードでは複数画像入力の例を示します。

OpenAI 互換

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 中国 (北京) リージョン。{WorkspaceId} をご利用の Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)

# 単一画像入力の例 (思考モード有効)
completion = client.chat.completions.create(
    model="kimi-k2.6",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "What scene is depicted in the image?"},
                {
                    "type": "image_url",
                    "image_url": {
                        "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241022/emyrja/dog_and_girl.jpeg"
                    }
                }
            ]
        }
    ],
    extra_body={"enable_thinking":True}  # 思考モードを有効にする
)

# 思考プロセスを出力
if hasattr(completion.choices[0].message, 'reasoning_content') and completion.choices[0].message.reasoning_content:
    print("\n" + "=" * 20 + "Thinking Process" + "=" * 20 + "\n")
    print(completion.choices[0].message.reasoning_content)

# 完全な応答を出力
print("\n" + "=" * 20 + "Complete Response" + "=" * 20 + "\n")
print(completion.choices[0].message.content)

# 複数画像入力の例 (思考モード有効、使用するにはコメントを解除)
# completion = client.chat.completions.create(
#     model="kimi-k2.6",
#     messages=[
#         {
#             "role": "user",
#             "content": [
#                 {"type": "text", "text": "What do these images depict?"},
#                 {
#                     "type": "image_url",
#                     "image_url": {"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241022/emyrja/dog_and_girl.jpeg"}
#                 },
#                 {
#                     "type": "image_url",
#                     "image_url": {"url": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/tiger.png"}
#                 }
#             ]
#         }
#     ],
#     extra_body={"enable_thinking":True}
# )
#
# # 思考プロセスと完全な応答を出力
# if hasattr(completion.choices[0].message, 'reasoning_content') and completion.choices[0].message.reasoning_content:
#     print("\nThinking Process:\n" + completion.choices[0].message.reasoning_content)
# print("\nComplete Response:\n" + completion.choices[0].message.content)
import OpenAI from "openai";
import process from 'process';

const openai = new OpenAI({
    apiKey: process.env.DASHSCOPE_API_KEY,
    // 中国 (北京) リージョン。{WorkspaceId} をご利用の Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    baseURL: 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1'
});

// 単一画像入力の例 (思考モード有効)
const completion = await openai.chat.completions.create({
    model: 'kimi-k2.6',
    messages: [
        {
            role: 'user',
            content: [
                { type: 'text', text: 'What scene is depicted in the image?' },
                {
                    type: 'image_url',
                    image_url: {
                        url: 'https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241022/emyrja/dog_and_girl.jpeg'
                    }
                }
            ]
        }
    ],
    enable_thinking: true  // 思考モードを有効にする
});

// 思考プロセスを出力
if (completion.choices[0].message.reasoning_content) {
    console.log('\n' + '='.repeat(20) + 'Thinking Process' + '='.repeat(20) + '\n');
    console.log(completion.choices[0].message.reasoning_content);
}

// 完全な応答を出力
console.log('\n' + '='.repeat(20) + 'Complete Response' + '='.repeat(20) + '\n');
console.log(completion.choices[0].message.content);

// 複数画像入力の例 (思考モード有効、使用するにはコメントを解除)
// const multiCompletion = await openai.chat.completions.create({
//     model: 'kimi-k2.6',
//     messages: [
//         {
//             role: 'user',
//             content: [
//                 { type: 'text', text: 'What do these images depict?' },
//                 {
//                     type: 'image_url',
//                     image_url: { url: 'https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241022/emyrja/dog_and_girl.jpeg' }
//                 },
//                 {
//                     type: 'image_url',
//                     image_url: { url: 'https://dashscope.oss-cn-beijing.aliyuncs.com/images/tiger.png' }
//                 }
//             ]
//         }
//     ],
//     enable_thinking: true
// });
//
// // 思考プロセスと完全な応答を出力
// if (multiCompletion.choices[0].message.reasoning_content) {
//     console.log('\nThinking Process:\n' + multiCompletion.choices[0].message.reasoning_content);
// }
// console.log('\nComplete Response:\n' + multiCompletion.choices[0].message.content);
# 中国 (北京) リージョン。 {WorkspaceId} をお使いの Bailian ワークスペース ID に置き換えます。 URL はリージョンによって異なります。
curl -X POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "kimi-k2.6",
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "What scene is depicted in the image?"
                },
                {
                    "type": "image_url",
                    "image_url": {
                        "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"
                    }
                }
            ]
        }
    ],
    "enable_thinking": true
}'

# 複数イメージ入力の例 (コメントを解除して使用します)
# 中国 (北京) リージョン。 {WorkspaceId} をお使いの Bailian ワークスペース ID に置き換えます。 URL はリージョンによって異なります。
# curl -X POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
# -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
# -H "Content-Type: application/json" \
# -d '{
#     "model": "kimi-k2.6",
#     "messages": [
#         {
#             "role": "user",
#             "content": [
#                 {
#                     "type": "text",
#                     "text": "What do these images depict?"
#                 },
#                 {
#                     "type": "image_url",
#                     "image_url": {
#                         "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"
#                     }
#                 },
#                 {
#                     "type": "image_url",
#                     "image_url": {
#                         "url": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/tiger.png"
#                     }
#                 }
#             ]
#         }
#     ],
#     "enable_thinking": true,
#     "stream": false
# }'

DashScope

import os
import dashscope
from dashscope import MultiModalConversation
# 中国 (北京) リージョンの構成。{WorkspaceId} を実際のワークスペース ID に置き換えてください。他のリージョンについては、対応するベース URL を使用してください。
dashscope.base_http_api_url = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1"

# 単一画像入力の例 (思考モード有効)
response = MultiModalConversation.call(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    model="kimi-k2.6",
    messages=[
        {
            "role": "user",
            "content": [
                {"text": "What scene is depicted in the image?"},
                {"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241022/emyrja/dog_and_girl.jpeg"}
            ]
        }
    ],
    enable_thinking=True  # 思考モードを有効にする
)

# 思考プロセスを出力
if hasattr(response.output.choices[0].message, 'reasoning_content') and response.output.choices[0].message.reasoning_content:
    print("\n" + "=" * 20 + "Thinking Process" + "=" * 20 + "\n")
    print(response.output.choices[0].message.reasoning_content)

# 完全な応答を出力
print("\n" + "=" * 20 + "Complete Response" + "=" * 20 + "\n")
print(response.output.choices[0].message.content[0]["text"])

# 複数画像入力の例 (思考モード有効、使用するにはコメントを解除)
# response = MultiModalConversation.call(
#     api_key=os.getenv("DASHSCOPE_API_KEY"),
#     model="kimi-k2.6",
#     messages=[
#         {
#             "role": "user",
#             "content": [
#                 {"text": "What do these images depict?"},
#                 {"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241022/emyrja/dog_and_girl.jpeg"},
#                 {"image": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/tiger.png"}
#             ]
#         }
#     ],
#     enable_thinking=True
# )
#
# # 思考プロセスと完全な応答を出力
# if hasattr(response.output.choices[0].message, 'reasoning_content') and response.output.choices[0].message.reasoning_content:
#     print("\nThinking Process:\n" + response.output.choices[0].message.reasoning_content)
# print("\nComplete Response:\n" + response.output.choices[0].message.content[0]["text"])
// DashScope SDK v2.22.24 以降が必要です。
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.common.MultiModalMessage;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class KimiK26MultiModalExample {
    public static void main(String[] args) {
        // 中国 (北京) リージョンの構成。{WorkspaceId} を実際のワークスペース ID に置き換えてください。他のリージョンについては、対応するベース URL を使用してください。
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1";
        try {
            // 単一画像入力の例 (思考モード有効)
            MultiModalConversation conv = new MultiModalConversation();

            // メッセージ本文を構築
            Map<String, Object> textContent = new HashMap<>();
            textContent.put("text", "What scene is depicted in the image?");

            Map<String, Object> imageContent = new HashMap<>();
            imageContent.put("image", "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241022/emyrja/dog_and_girl.jpeg");

            MultiModalMessage userMessage = MultiModalMessage.builder()
                    .role(Role.USER.getValue())
                    .content(Arrays.asList(textContent, imageContent))
                    .build();

            // リクエストパラメーターを構築
            MultiModalConversationParam param = MultiModalConversationParam.builder()
                    // 環境変数が設定されていない場合は、これを Model Studio の API キーに置き換えます。
                    .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                    .model("kimi-k2.6")
                    .messages(Arrays.asList(userMessage))
                    .enableThinking(true)  // 思考モードを有効にする
                    .build();

            // モデルを呼び出す
            MultiModalConversationResult result = conv.call(param);

            // 応答を出力
            String content = (String) result.getOutput().getChoices().get(0).getMessage().getContent().get(0).get("text");
            System.out.println("Response: " + content);

            // 思考モードが有効な場合、思考プロセスを出力
            if (result.getOutput().getChoices().get(0).getMessage().getReasoningContent() != null) {
                System.out.println("\nThinking Process: " +
                    result.getOutput().getChoices().get(0).getMessage().getReasoningContent());
            }

            // 複数画像入力の例 (使用するにはコメントを解除)
            // Map<String, Object> imageContent1 = new HashMap<>();
            // imageContent1.put("image", "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241022/emyrja/dog_and_girl.jpeg");
            // Map<String, Object> imageContent2 = new HashMap<>();
            // imageContent2.put("image", "https://dashscope.oss-cn-beijing.aliyuncs.com/images/tiger.png");
            //
            // Map<String, Object> textContent2 = new HashMap<>();
            // textContent2.put("text", "What do these images depict?");
            //
            // MultiModalMessage multiImageMessage = MultiModalMessage.builder()
            //         .role(Role.USER.getValue())
            //         .content(Arrays.asList(textContent2, imageContent1, imageContent2))
            //         .build();
            //
            // MultiModalConversationParam multiParam = MultiModalConversationParam.builder()
            //         .apiKey(System.getenv("DASHSCOPE_API_KEY"))
            //         .model("kimi-k2.6")
            //         .messages(Arrays.asList(multiImageMessage))
            //         .enableThinking(true)
            //         .build();
            //
            // MultiModalConversationResult multiResult = conv.call(multiParam);
            // System.out.println(multiResult.getOutput().getChoices().get(0).getMessage().getContent().get(0).get("text"));

        } catch (ApiException | NoApiKeyException | UploadFileException e) {
            System.err.println("Call failed: " + e.getMessage());
        }
    }
}
# 中国 (北京) リージョン。{WorkspaceId} をお使いの Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
curl -X POST "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "kimi-k2.6",
    "input": {
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "text": "イメージにはどのようなシーンが描かれていますか?"
                    },
                    {
                        "image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"
                    }
                ]
            }
        ]
    },
    "parameters": {
        "enable_thinking": true
    }
}'

# 複数イメージ入力の例 (コメントを解除して使用します)
# 中国 (北京) リージョン。{WorkspaceId} をお使いの Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
# curl -X POST "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation" \
# -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
# -H "Content-Type: application/json" \
# -d '{
#     "model": "kimi-k2.6",
#     "input": {
#         "messages": [
#             {
#                 "role": "user",
#                 "content": [
#                     {
#                         "text": "これらのイメージは何を描写していますか?"
#                     },
#                     {
#                         "image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"
#                     },
#                     {
#                         "image": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/tiger.png"
#                     }
#                 ]
#             }
#         ]
#     },
#     "parameters": {
#         "enable_thinking": true
#     }
# }'

動画理解

動画ファイル

kimi-k2.7-code、kimi-k2.6、および kimi-k2.5 モデルは、一連のフレームを抽出して動画を分析します。次のパラメーターでフレーム抽出戦略をコントロールできます:

  • fps:フレーム抽出周波数をコントロールします。抽出されるフレーム間の間隔は f p s 1 ​ 秒です。値は [0.1, 10] の範囲内である必要があります。デフォルト値は 2.0 です。

    • 動きの激しいシーンの場合:より多くの詳細をキャプチャするために、より高い fps 値を設定します。
    • 静的な動画や長時間の動画の場合:処理効率を向上させるために、より低い fps 値を設定します。
  • max_frames:動画から抽出するフレームの最大数を指定します。デフォルトおよび最大値は 2000 です。

    fps 値から計算されたフレーム数がこの制限を超えた場合、システムは max_frames の制限内に収まるようにフレームを均等に自動抽出します。このパラメーターは、DashScope SDK を使用する場合にのみ使用できます。

OpenAI 互換

OpenAI SDK または HTTP リクエストを使用してモデルに動画ファイルを渡す場合、ユーザーメッセージの "type" パラメーターを "video_url" に設定します。

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 中国 (北京) リージョン。{WorkspaceId} をご利用の Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)

completion = client.chat.completions.create(
    model="kimi-k2.6",
    messages=[
        {
            "role": "user",
            "content": [
                # 動画ファイルを直接渡す場合、"type" パラメーターを "video_url" に設定します。
                {
                    "type": "video_url",
                    "video_url": {
                        "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241115/cqqkru/1.mp4"
                    },
                    "fps": 2
                },
                {
                    "type": "text",
                    "text": "What is the content of this video?"
                }
            ]
        }
    ]
)

print(completion.choices[0].message.content)
import OpenAI from "openai";

const openai = new OpenAI({
    apiKey: process.env.DASHSCOPE_API_KEY,
    // 中国 (北京) リージョン。{WorkspaceId} をご利用の Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    baseURL: "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1"
});

async function main() {
    const response = await openai.chat.completions.create({
        model: "kimi-k2.6",
        messages: [
            {
                role: "user",
                content: [
                    // 動画ファイルを直接渡す場合、"type" パラメーターを "video_url" に設定します。
                    {
                        type: "video_url",
                        video_url: {
                            "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241115/cqqkru/1.mp4"
                        },
                        "fps": 2
                    },
                    {
                        type: "text",
                        text: "What is the content of this video?"
                    }
                ]
            }
        ]
    });

    console.log(response.choices[0].message.content);
}

main();
# 中国 (北京) リージョン。{WorkspaceId} をご利用の Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
curl -X POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "kimi-k2.6",
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "video_url",
            "video_url": {
              "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241115/cqqkru/1.mp4"
            },
            "fps":2
          },
          {
            "type": "text",
            "text": "What is the content of this video?"
          }
        ]
      }
    ]
  }'

DashScope

import dashscope
import os

# 中国 (北京) リージョン。{WorkspaceId} をご利用の Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
dashscope.base_http_api_url = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1"

messages = [
    {"role": "user",
        "content": [
            # fps パラメーターはフレーム抽出周波数を設定します。フレーム間の間隔は 1/fps 秒です。
            {"video": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241115/cqqkru/1.mp4","fps":2},
            {"text": "What is the content of this video?"}
        ]
    }
]

response = dashscope.MultiModalConversation.call(
    # DASHSCOPE_API_KEY 環境変数が設定されていない場合は、この行を Model Studio API キーに置き換えます:api_key="sk-xxx"
    api_key=os.getenv('DASHSCOPE_API_KEY'),
    model='kimi-k2.6',
    messages=messages
)

print(response.output.choices[0].message.content[0]["text"])
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.common.MultiModalMessage;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;

public class Main {
    public static void simpleMultiModalConversationCall()
            throws ApiException, NoApiKeyException, UploadFileException {
        MultiModalConversation conv = new MultiModalConversation();
        // fps パラメーターはフレーム抽出周波数を設定します。フレーム間の間隔は 1/fps 秒です。
        Map<String, Object> params = new HashMap<>();
        params.put("video", "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241115/cqqkru/1.mp4");
        params.put("fps", 2);
        MultiModalMessage userMessage = MultiModalMessage.builder().role(Role.USER.getValue())
                .content(Arrays.asList(
                        params,
                        Collections.singletonMap("text", "What is the content of this video?"))).build();
        MultiModalConversationParam param = MultiModalConversationParam.builder()
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                .model("kimi-k2.6")
                .messages(Arrays.asList(userMessage))
                .build();
        MultiModalConversationResult result = conv.call(param);
        System.out.println(result.getOutput().getChoices().get(0).getMessage().getContent().get(0).get("text"));
    }
    public static void main(String[] args) {
        // 中国 (北京) リージョンの構成。{WorkspaceId} を実際のワークスペース ID に置き換えてください。他のリージョンについては、対応するベース URL を使用してください。
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1";
        try {
            simpleMultiModalConversationCall();
        } catch (ApiException | NoApiKeyException | UploadFileException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }
}
# 中国 (北京) リージョン。{WorkspaceId} をお使いの Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
curl -X POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
    "model": "kimi-k2.6",
    "input":{
        "messages":[
            {"role": "user","content": [{"video": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241115/cqqkru/1.mp4","fps":2},
            {"text": "What is the content of this video?"}]}]}
}'

画像リスト

動画を画像リスト (事前に抽出されたフレーム) として提供する場合、fps パラメーターを使用して元の動画のフレーム抽出レートを指定します。この値は、フレームが f p s 1 ​ 秒ごとに抽出されたことを示し、モデルがイベントのシーケンス、持続時間、および動的な変化をよりよく理解できるようにします。

OpenAI 互換

OpenAI SDK または HTTP リクエストを使用して動画を画像リストとして渡す場合、ユーザーメッセージの "type" パラメーターを "video" に設定します。

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 中国 (北京) リージョン。 {WorkspaceId} をお使いの Bailian ワークスペース ID に置き換えます。 URL はリージョンによって異なります。
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)

completion = client.chat.completions.create(
    model="kimi-k2.6",
    messages=[{"role": "user","content": [
        # イメージリストを渡す場合、ユーザーメッセージの "type" パラメーターを "video" に設定します。
         {"type": "video","video": [
         "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/xzsgiz/football1.jpg",
         "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/tdescd/football2.jpg",
         "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/zefdja/football3.jpg",
         "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/aedbqh/football4.jpg"],
         "fps":2},
         {"type": "text","text": "Describe the action in this video."},
    ]}]
)

print(completion.choices[0].message.content)
import OpenAI from "openai";

const openai = new OpenAI({
    apiKey: process.env.DASHSCOPE_API_KEY,
    // 中国 (北京) リージョン。{WorkspaceId} をお使いの Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    baseURL: "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1"
});

async function main() {
    const response = await openai.chat.completions.create({
        model: "kimi-k2.6",
        messages: [{
            role: "user",
            content: [
                {
                    // イメージリストを渡す場合、ユーザーメッセージの "type" パラメーターを "video" に設定します。
                    type: "video",
                    video: [
                        "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/xzsgiz/football1.jpg",
                        "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/tdescd/football2.jpg",
                        "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/zefdja/football3.jpg",
                        "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/aedbqh/football4.jpg"],
                        "fps":2
                },
                {
                    type: "text",
                    text: "Describe the action in this video."
                }
            ]
        }]
    });
    console.log(response.choices[0].message.content);
}

main();
# 中国 (北京) リージョン。 「{WorkspaceId}」をお客様の百煉ワークスペース ID に置き換えます。 URL はリージョンによって異なります。
curl -X POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
    "model": "kimi-k2.6",
    "messages": [{"role": "user","content": [{"type": "video","video": [
                  "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/xzsgiz/football1.jpg",
                  "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/tdescd/football2.jpg",
                  "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/zefdja/football3.jpg",
                  "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/aedbqh/football4.jpg"],
                  "fps":2},
                {"type": "text","text": "このビデオでのアクションを説明してください。"}]}]
}'

DashScope

import os
import dashscope

# 中国 (北京) リージョン。{WorkspaceId} をお使いの Bailian ワークスペース ID に置き換えます。URL はリージョンによって異なります。
dashscope.base_http_api_url = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1"

messages = [{"role": "user",
             "content": [
                 {"video":["https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/xzsgiz/football1.jpg",
                           "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/tdescd/football2.jpg",
                           "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/zefdja/football3.jpg",
                           "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/aedbqh/football4.jpg"],
                   "fps":2},
                 {"text": "Describe the action in this video."}]}]
response = dashscope.MultiModalConversation.call(
    # DASHSCOPE_API_KEY 環境変数が設定されていない場合は、この行をお使いの Model Studio API キーに置き換えます: api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    model='kimi-k2.6',
    messages=messages
)
print(response.output.choices[0].message.content[0]["text"])
// DashScope SDK v2.21.10 以降が必要です。
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.common.MultiModalMessage;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.Constants;

public class Main {
    // 中国 (北京) リージョン。{WorkspaceId} をご利用の Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    static {Constants.baseHttpApiUrl="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1";}

    private static final String MODEL_NAME = "kimi-k2.6";
    public static void videoImageListSample() throws ApiException, NoApiKeyException, UploadFileException {
        MultiModalConversation conv = new MultiModalConversation();
        Map<String, Object> params = new HashMap<>();
        params.put("video", Arrays.asList("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241108/xzsgiz/football1.jpg",
                "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241108/tdescd/football2.jpg",
                "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241108/zefdja/football3.jpg",
                "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241108/aedbqh/football4.jpg"));
        params.put("fps", 2);
        MultiModalMessage userMessage = MultiModalMessage.builder()
                .role(Role.USER.getValue())
                .content(Arrays.asList(
                        params,
                        Collections.singletonMap("text", "Describe the action in this video.")))
                .build();
        MultiModalConversationParam param = MultiModalConversationParam.builder()
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                .model(MODEL_NAME)
                .messages(Arrays.asList(userMessage)).build();
        MultiModalConversationResult result = conv.call(param);
        System.out.print(result.getOutput().getChoices().get(0).getMessage().getContent().get(0).get("text"));
    }
    public static void main(String[] args) {
        try {
            videoImageListSample();
        } catch (ApiException | NoApiKeyException | UploadFileException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }
}
# 中国 (北京) リージョン。{WorkspaceId} をご利用の Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
curl -X POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
  "model": "kimi-k2.6",
  "input": {
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "video": [
              "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241108/xzsgiz/football1.jpg",
              "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241108/tdescd/football2.jpg",
              "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241108/zefdja/football3.jpg",
              "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241108/aedbqh/football4.jpg"
            ],
            "fps":2

          },
          {
            "text": "Describe the action in this video."
          }
        ]
      }
    ]
  }
}'

ローカルファイルの受け渡し

以下の例では、ローカルファイルの受け渡し方法を示します。OpenAI 互換 API は Base64 エンコーディングのみをサポートしますが、DashScope は Base64 エンコーディングとファイルパスの両方をサポートします。

OpenAI 互換

Base64 エンコーディングを使用してローカルファイルを渡すには、データ URL を構築します。手順については、「データ URL の構築」をご参照ください。

from openai import OpenAI
import os
import base64

# エンコード関数:ローカルファイルを Base64 エンコードされた文字列に変換します。
def encode_image(image_path):
    with open(image_path, "rb") as image_file:
        return base64.b64encode(image_file.read()).decode("utf-8")

# "xxx/eagle.png" をローカル画像の絶対パスに置き換えてください。
base64_image = encode_image("xxx/eagle.png")

client = OpenAI(
    api_key=os.getenv('DASHSCOPE_API_KEY'),
    # 中国 (北京) リージョン。{WorkspaceId} をご利用の Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
    model="kimi-k2.6",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "image_url",
                    "image_url": {"url": f"data:image/png;base64,{base64_image}"},
                },
                {"type": "text", "text": "What scene is depicted in the image?"},
            ],
        }
    ],
)
print(completion.choices[0].message.content)

# 以下の例では、ローカルの動画ファイルとローカルの画像リストを渡す方法を示します。

# [ローカル動画ファイル] ローカル動画をデータ URL としてエンコードし、video_url パラメーターに渡します:
#   def encode_video_to_data_url(video_path):
#       with open(video_path, "rb") as f:
#           return "data:video/mp4;base64," + base64.b64encode(f.read()).decode("utf-8")

#   video_data_url = encode_video_to_data_url("xxx/local.mp4")
#   content = [{"type": "video_url", "video_url": {"url": video_data_url}, "fps": 2}, {"type": "text", "text": "What is the content of this video?"}]

# [ローカル画像リスト] 複数のローカル画像を Base64 でエンコードし、リストとして video パラメーターに渡します:
#   image_data_urls = [f"data:image/jpeg;base64,{encode_image(p)}" for p in ["xxx/f1.jpg", "xxx/f2.jpg", "xxx/f3.jpg", "xxx/f4.jpg"]]
#   content = [{"type": "video", "video": image_data_urls, "fps": 2}, {"type": "text", "text": "Describe the sequence of events in this video."}]
import OpenAI from "openai";
import { readFileSync } from 'fs';

const openai = new OpenAI(
    {
        apiKey: process.env.DASHSCOPE_API_KEY,
        // 中国 (北京) リージョン。{WorkspaceId} をご利用の Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
        baseURL: "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1"
    }
);

const encodeImage = (imagePath) => {
    const imageFile = readFileSync(imagePath);
    return imageFile.toString('base64');
  };
// "xxx/eagle.png" をローカル画像の絶対パスに置き換えてください。
const base64Image = encodeImage("xxx/eagle.png")
async function main() {
    const completion = await openai.chat.completions.create({
        model: "kimi-k2.6",
        messages: [
            {"role": "user",
             "content": [{"type": "image_url",
                        "image_url": {"url": `data:image/png;base64,${base64Image}`},},
                        {"type": "text", "text": "What scene is depicted in the image?"}]}]
    });
    console.log(completion.choices[0].message.content);
}

main();

// 以下の例では、ローカルの動画ファイルとローカルの画像リストを渡す方法を示します。

// [ローカル動画ファイル] ローカル動画をデータ URL としてエンコードし、video_url パラメーターに渡します:
//   const encodeVideoToDataUrl = (videoPath) => "data:video/mp4;base64," + readFileSync(videoPath).toString("base64");
//   const videoDataUrl = encodeVideoToDataUrl("xxx/local.mp4");
//   content: [{ type: "video_url", video_url: { url: videoDataUrl }, fps: 2 }, { type: "text", text: "What is the content of this video?" }]

// [ローカル画像リスト] 複数のローカル画像を Base64 でエンコードし、リストとして video パラメーターに渡します:
//   const imageDataUrls = ["xxx/f1.jpg","xxx/f2.jpg","xxx/f3.jpg","xxx/f4.jpg"].map(p => `data:image/jpeg;base64,${encodeImage(p)}`);
//   content: [{ type: "video", video: imageDataUrls, fps: 2 }, { type: "text", text: "Describe the sequence of events in this video." }]

//   messages: [{"role": "user", "content": content}]
//   Then call openai.chat.completions.create({model: "kimi-k2.6", messages: messages})

DashScope

Base64 エンコーディング

Base64 エンコーディングを使用してローカルファイルを渡すには、データ URL を構築します。手順については、「データ URL の構築」をご参照ください。

import base64
import os
import dashscope
from dashscope import MultiModalConversation

# 中国 (北京) リージョン。{WorkspaceId} をご利用の Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
dashscope.base_http_api_url = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1"

# エンコード関数:ローカルファイルを Base64 エンコードされた文字列に変換します。
def encode_image(image_path):
    with open(image_path, "rb") as image_file:
        return base64.b64encode(image_file.read()).decode("utf-8")

# "xxx/eagle.png" をローカル画像の絶対パスに置き換えてください。
base64_image = encode_image("xxx/eagle.png")

messages = [
    {
        "role": "user",
        "content": [
            {"image": f"data:image/png;base64,{base64_image}"},
            {"text": "What scene is depicted in the image?"},
        ],
    },
]
response = MultiModalConversation.call(
    # DASHSCOPE_API_KEY 環境変数が設定されていない場合は、Model Studio API キーを直接渡します。例:api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    model="kimi-k2.6",
    messages=messages,
)
print(response.output.choices[0].message.content[0]["text"])

# 以下の例では、ローカルの動画ファイルとローカルの画像リストを渡す方法を示します。

# [ローカル動画ファイル]
#   video_data_url = "data:video/mp4;base64," + base64.b64encode(open("xxx/local.mp4","rb").read()).decode("utf-8")
#   content: [{"video": video_data_url, "fps": 2}, {"text": "What is the content of this video?"}]

# [ローカル画像リスト]
#   image_data_urls = [f"data:image/jpeg;base64,{encode_image(p)}" for p in ["xxx/f1.jpg","xxx/f2.jpg","xxx/f3.jpg","xxx/f4.jpg"]]
#   content: [{"video": image_data_urls, "fps": 2}, {"text": "Describe the sequence of events in this video."}]
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Base64;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import com.alibaba.dashscope.aigc.multimodalconversation.*;
import com.alibaba.dashscope.common.MultiModalMessage;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.Constants;

public class Main {

   // 中国 (北京) リージョン。{WorkspaceId} をご利用の Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
   static {Constants.baseHttpApiUrl="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1";}

    private static String encodeToBase64(String imagePath) throws IOException {
        Path path = Paths.get(imagePath);
        byte[] imageBytes = Files.readAllBytes(path);
        return Base64.getEncoder().encodeToString(imageBytes);
    }

    public static void callWithLocalFile(String localPath) throws ApiException, NoApiKeyException, UploadFileException, IOException {

        String base64Image = encodeToBase64(localPath);

        MultiModalConversation conv = new MultiModalConversation();
        MultiModalMessage userMessage = MultiModalMessage.builder().role(Role.USER.getValue())
                .content(Arrays.asList(
                        new HashMap<String, Object>() {{ put("image", "data:image/png;base64," + base64Image); }},
                        new HashMap<String, Object>() {{ put("text", "What scene is depicted in the image?"); }}
                )).build();

        MultiModalConversationParam param = MultiModalConversationParam.builder()
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                .model("kimi-k2.6")
                .messages(Arrays.asList(userMessage))
                .build();

        MultiModalConversationResult result = conv.call(param);
        System.out.println(result.getOutput().getChoices().get(0).getMessage().getContent().get(0).get("text"));
    }

    public static void main(String[] args) {
        try {
            // "xxx/eagle.png" をローカル画像の絶対パスに置き換えてください。
            callWithLocalFile("xxx/eagle.png");
        } catch (ApiException | NoApiKeyException | UploadFileException | IOException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }

    // 以下の例では、ローカルの動画ファイルとローカルの画像リストを渡す方法を示します。
    // [ローカル動画ファイル]
    // String base64Video = encodeToBase64(localPath);
    // MultiModalConversation conv = new MultiModalConversation();
   //  MultiModalMessage userMessage = MultiModalMessage.builder().role(Role.USER.getValue())
   //             .content(Arrays.asList(
   //                     new HashMap<String, Object>() {{ put("video", "data:video/mp4;base64," + base64Video); }},
   //                     new HashMap<String, Object>() {{ put("text", "What scene is depicted in this video?"); }}
   //             )).build();

    // [ローカル画像リスト]
    // List<String> urls = Arrays.asList(
    //                                   "data:image/jpeg;base64,"+encodeToBase64("path/f1.jpg"),
    //                                   "data:image/jpeg;base64,"+encodeToBase64("path/f2.jpg"),
    //                                   "data:image/jpeg;base64,"+encodeToBase64("path/f3.jpg"),
    //                                   "data:image/jpeg;base64,"+encodeToBase64("path/f4.jpg"));
   //  MultiModalConversation conv = new MultiModalConversation();
   //  MultiModalMessage userMessage = MultiModalMessage.builder().role(Role.USER.getValue())
   //             .content(Arrays.asList(
   //                     new HashMap<String, Object>() {{ put("video", urls); }},
   //                     new HashMap<String, Object>() {{ put("text", "What scene is depicted in this video?"); }}
   //             )).build();

}

ファイルパス

ローカルファイルのパスをモデルに直接渡すことができます。この方法は DashScope Python および Java SDK でのみサポートされており、DashScope HTTP または OpenAI 互換 API では利用できません。以下の表は、各プログラミング言語とオペレーティングシステムで必要なファイルパスのフォーマットを示しています。

ファイルパスの指定 (画像の例)

システム

SDK

パスフォーマット

例

Linux または macOS

Python SDK

file://{ファイルの絶対パス}

file:///home/images/test.png

Java SDK

Windows

Python SDK

file://{ファイルの絶対パス}

file://D:/images/test.png

Java SDK

file:///{ファイルの絶対パス}

file:///D:/images/test.png

import os
from dashscope import MultiModalConversation
import dashscope

# 中国 (北京) リージョン。{WorkspaceId} をご利用の Bailian ワークスペース ID に置き換えてください。URL はリージョンによって異なります。
dashscope.base_http_api_url = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1"

# "xxx/eagle.png" をローカル画像の絶対パスに置き換えてください。
local_path = "xxx/eagle.png"
image_path = f"file://{local_path}"
messages = [
                {'role':'user',
                'content': [{'image': image_path},
                            {'text': 'What scene is depicted in the image?'}]}]
response = MultiModalConversation.call(
    api_key=os.getenv('DASHSCOPE_API_KEY'),
    model='kimi-k2.6',
    messages=messages)
print(response.output.choices[0].message.content[0]["text"])

# 以下の例では、ファイルパスを使用してローカルの動画とローカルの画像リストを渡す方法を示します。
# [ローカル動画ファイル]
#  video_path = "file:///path/to/local.mp4"
#  content: [{"video": video_path, "fps": 2}, {"text": "What is the content of this video?"}]

# [ローカル画像リスト]
# image_paths = ["file:///path/f1.jpg", "file:///path/f2.jpg", "file:///path/f3.jpg", "file:///path/f4.jpg"]
# content: [{"video": image_paths, "fps": 2}, {"text": "Describe the sequence of events in this video."}]
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.common.MultiModalMessage;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.Constants;

public class Main {
    public static void callWithLocalFile(String localPath)
            throws ApiException, NoApiKeyException, UploadFileException {
        String filePath = "file://"+localPath;
        MultiModalConversation conv = new MultiModalConversation();
        MultiModalMessage userMessage = MultiModalMessage.builder().role(Role.USER.getValue())
                .content(Arrays.asList(new HashMap<String, Object>(){{put("image", filePath);}},
                        new HashMap<String, Object>(){{put("text", "What scene is depicted in the image?");}})).build();
        MultiModalConversationParam param = MultiModalConversationParam.builder()
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                .model("kimi-k2.6")
                .messages(Arrays.asList(userMessage))
                .build();
        MultiModalConversationResult result = conv.call(param);
        System.out.println(result.getOutput().getChoices().get(0).getMessage().getContent().get(0).get("text"));}

    public static void main(String[] args) {
        // 中国 (北京) リージョンの構成。{WorkspaceId} を実際のワークスペース ID に置き換えてください。他のリージョンについては、対応するベース URL を使用してください。
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1";
        try {
            // "xxx/eagle.png" をローカル画像の絶対パスに置き換えてください。
            callWithLocalFile("xxx/eagle.png");
        } catch (ApiException | NoApiKeyException | UploadFileException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }

    // 以下の例では、ファイルパスを使用してローカルの動画とローカルの画像リストを渡す方法を示します。

    // [ローカル動画ファイル]
    //  String filePath = "file://"+localPath;
    //    MultiModalConversation conv = new MultiModalConversation();
    //    MultiModalMessage userMessage = MultiModalMessage.builder().role(Role.USER.getValue())
    //            .content(Arrays.asList(new HashMap<String, Object>(){{put("video", filePath);}},
    //                    new HashMap<String, Object>(){{put("text", "What scene is depicted in the video?");}})).build();

    // [ローカル画像リスト]

    //    MultiModalConversation conv = new MultiModalConversation();
    //    List<String> filePath = Arrays.asList("file:///path/f1.jpg", "file:///path/f2.jpg", "file:///path/f3.jpg", "file:///path/f4.jpg")
    //    MultiModalMessage userMessage = MultiModalMessage.builder().role(Role.USER.getValue())
    //            .content(Arrays.asList(new HashMap<String, Object>(){{put("video", filePath);}},
    //                    new HashMap<String, Object>(){{put("text", "What scene is depicted in the video?");}})).build();
}

ファイルの制限

画像の制限

  • 画像解像度:
    • 最小サイズ:幅と高さはそれぞれ 10 ピクセルを超える必要があります。
    • アスペクト比:最も長い辺と最も短い辺の比率が 200:1 を超えてはなりません。
    • 最大解像度:推奨される最大解像度は 8K (7680x4320) です。解像度が高いと、ファイルサイズが大きくなったり、ネットワーク転送が遅くなったりして、API 呼び出しがタイムアウトする可能性があります。
  • サポートされている画像フォーマット
    • 4K(3840x2160) 未満の解像度では、次のフォーマットがサポートされています:

      画像フォーマット

      ファイル拡張子

      MIME タイプ

      BMP

      .bmp

      image/bmp

      JPEG

      .jpe, .jpeg, .jpg

      image/jpeg

      PNG

      .png

      image/png

      TIFF

      .tif, .tiff

      image/tiff

      WEBP

      .webp

      image/webp

      HEIC

      .heic

      image/heic

    • 4K (3840x2160) から 8K (7680x4320) の解像度では、JPEG、JPG、PNG のみがサポートされています。

  • 画像サイズ:
    • 公開 URL またはローカルパス経由で画像を提供する場合、そのサイズは 10 MB を超えてはなりません。
    • Base64 エンコーディングを使用する場合、エンコードされた文字列は 10 MB を超えてはなりません。

    ファイルを圧縮するには、「画像または動画を圧縮してサイズ制限を満たす方法」をご参照ください。

  • サポートされる画像の数:複数の画像を提供する場合、すべての画像とテキストの合計トークン数は、モデルの最大入力制限を超えてはなりません。

動画の制限

  • 画像リストとして:4〜2,000 枚の画像。

  • 動画ファイルとして:
    • 動画サイズ:
      • 公開 URL 経由:最大 2 GB。
      • Base64 エンコーディング経由:エンコードされた文字列は 10 MB 未満である必要があります。
      • ローカルファイルパス経由:最大 100 MB。
    • 動画の長さ:2 秒から 1 時間。

  • 動画フォーマット:MP4、AVI、MKV、MOV、FLV、WMV などのフォーマットがサポートされています。

  • 動画解像度:厳密な解像度制限はありませんが、最良の結果を得るためには 2K 以下を使用してください。解像度を高くしても、モデルの理解度が向上することなく、処理時間が増加します。

  • 音声理解:モデルは動画ファイル内の音声トラックを処理しません。

その他の機能

モデル

マルチターン対話

ディープシンキング

関数呼び出し

構造化出力

Web 検索

プレフィックス補完

コンテキストキャッシュ

kimi-k2.7-code

サポート

サポート

サポート

非サポート

非サポート

非サポート

サポート

kimi-k2.6

サポート

サポート

サポート

非サポート

非サポート

非サポート

サポート

kimi-k2.5

サポート

サポート

サポート

非サポート

非サポート

非サポート

サポート

kimi-k2-thinking

サポート

サポート

サポート

サポート

非サポート

非サポート

サポート

Moonshot-Kimi-K2-Instruct

サポート

非サポート

サポート

非サポート

サポート

非サポート

サポート

デフォルトパラメーター

モデル

enable_thinking

temperature

top_p

presence_penalty

fps

max_frames

kimi-k2.7-code

true (思考モードのみ)

1.0

0.95

0.0

2

2000

kimi-k2.6

false

思考モード:1.0

ノンシンキングモード:0.6

両モード:0.95

両モード:0.0

2

2000

kimi-k2.5

false

思考モード:1.0

ノンシンキングモード:0.6

両モード:0.95

両モード:0.0

2

2000

kimi-k2-thinking

-

1.0

-

-

-

-

Moonshot-Kimi-K2-Instruct

-

0.6

1.0

0

-

-

ハイフン (-) は、パラメーターが該当しないことを示します。

モデルと課金

Kimi シリーズは、Moonshot AI の大規模言語モデルです。

  • kimi-k2.7-code:コーディングに最も優れた Kimi モデルです。長文コンテキストの命令により忠実に従い、プログラミングタスクでより高い成功率を達成します。テキスト、画像、動画入力、思考モード、対話、エージェントタスクをサポートします。
  • kimi-k2.6:Kimi シリーズで最新かつ最も高性能なモデルです。長期間のコーディング、命令追従、自己修正においてパフォーマンスが向上しています。テキスト、画像、動画入力、思考モードとノンシンキングモード、対話、エージェントタスクをサポートします。
  • kimi-k2.5:エージェントタスク、コード生成、視覚理解、その他の一般的な知能タスクに関するオープンソースのベンチマークで最先端 (SOTA) のパフォーマンスを達成します。画像、動画、テキスト入力、思考モードとノンシンキングモード、対話、エージェントタスクをサポートします。
  • kimi-k2-thinking: ディープ思考モードにのみ対応しており、reasoning_content フィールドを介して推論プロセスを公開します。コーディングとツール呼び出しに優れており、論理分析、計画、または深い理解を必要とするユースケースに適しています。
  • Moonshot-Kimi-K2-Instruct:ディープシンキングをサポートしません。より低いレイテンシーで応答を生成し、迅速で直接的な回答が必要なユースケースに適しています。

kimi-k2.7-code の価格については、「モデル呼び出しの課金」をご参照ください。

価格とコンテキストウィンドウの詳細については、Model Studio コンソールをご参照ください。

課金は、入力および出力トークン数に基づきます。

思考モードでは、思考の連鎖が出力トークンとしてカウントされます。

エラーコード

モデルの呼び出しが失敗し、エラーメッセージが返された場合は、「エラーコード」をご参照ください。