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

Alibaba Cloud Model Studio:Anthropic 互換 Messages

最終更新日:Jun 29, 2026

3 つの設定を変更するだけで、既存の Anthropic アプリケーションを Model Studio に移行できます。このトピックでは、リクエストおよびレスポンスパラメーターについて、コード例を交えて説明します。

既存の Anthropic アプリケーションを Model Studio に移行するには、以下の設定を変更します。

  • api_keyModel Studio API キーに置き換えます。

  • base_url:以下に示す Model Studio のエンドポイントに置き換えます。

  • modelqwen3.7-plus などのサポートされているモデル名に置き換えます。

重要

Model Studio は、中国 (北京)、シンガポール、および中国 (香港) リージョン向けにワークスペース固有のドメインをリリースしました。新しい専用ドメインは、推論リクエストに対して優れたパフォーマンスと高い安定性を提供します。新しいドメインへの移行を推奨します:

  • 中国 (北京):https://dashscope.aliyuncs.com から https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com

  • シンガポール:https://dashscope-intl.aliyuncs.com から https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com

  • 中国 (香港):https://cn-hongkong.dashscope.aliyuncs.com から https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com

{WorkspaceId} はご利用のワークスペース ID で、Model Studio コンソールの [ワークスペース詳細] ページで確認できます。既存のドメインも引き続き完全に機能します。

シンガポール

SDK base_urlhttps://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic

HTTP リクエスト URL:POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic/v1/messages

中国 (北京)

SDK base_urlhttps://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/apps/anthropic

HTTP リクエスト URL:POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/apps/anthropic/v1/messages

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

SDK base_urlhttps://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/apps/anthropic

HTTP リクエスト URL:POST https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/apps/anthropic/v1/messages

米国 (バージニア)

SDK base_urlhttps://dashscope-us.aliyuncs.com/apps/anthropic

HTTP リクエスト URL:POST https://dashscope-us.aliyuncs.com/apps/anthropic/v1/messages

日本 (東京)

SDK base_urlhttps://{WorkspaceId}.ap-northeast-1.maas.aliyuncs.com/apps/anthropic

HTTP リクエスト URL:POST https://{WorkspaceId}.ap-northeast-1.maas.aliyuncs.com/apps/anthropic/v1/messages

ご利用の実際のワークスペース ID{WorkspaceId} を置き換えてください。

認証:Model Studio API キーx-api-key ヘッダーまたは Authorization: Bearer ヘッダーのいずれかで渡します。

リクエストボディ

基本的な呼び出し

Python

import anthropic
import os

client = anthropic.Anthropic(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # {WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
)

message = client.messages.create(
    model="qwen3.7-plus",
    max_tokens=1024,
    system="You are a helpful assistant",
    messages=[
        {
            "role": "user",
            "content": "Who are you?"
        }
    ],
    thinking={"type": "disabled"},
)

print(message.content[0].text)

TypeScript

import Anthropic from "@anthropic-ai/sdk";

const anthropic = new Anthropic({
  apiKey: process.env.DASHSCOPE_API_KEY,
  // {WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
  baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
});

async function main() {
  const message = await anthropic.messages.create({
    model: "qwen3.7-plus",
    max_tokens: 1024,
    system: "You are a helpful assistant",
    messages: [{
      role: "user",
      content: "Who are you?"
    }],
    thinking: { type: "disabled" },
  });

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

main().catch(console.error);

curl

curl -X POST "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic/v1/messages" \
  -H "Content-Type: application/json" \
  -H "x-api-key: $DASHSCOPE_API_KEY" \
  -d '{
    "model": "qwen3.7-plus",
    "max_tokens": 1024,
    "system": "You are a helpful assistant",
    "messages": [
        {
            "role": "user",
            "content": "Who are you?"
        }
    ],
    "thinking": {"type": "disabled"}
}'

ストリーミング

Python

import anthropic
import os

client = anthropic.Anthropic(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # {WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
)

stream = client.messages.create(
    model="qwen3.7-plus",
    max_tokens=1024,
    stream=True,
    messages=[
        {
            "role": "user",
            "content": "Give a brief introduction to artificial intelligence."
        }
    ],
    thinking={"type": "disabled"},
)

for chunk in stream:
    if chunk.type == "content_block_delta":
        if hasattr(chunk.delta, 'text'):
            print(chunk.delta.text, end="", flush=True)

TypeScript

import Anthropic from "@anthropic-ai/sdk";

async function main() {
  const anthropic = new Anthropic({
    apiKey: process.env.DASHSCOPE_API_KEY,
    // {WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
  });

  const stream = await anthropic.messages.create({
    model: "qwen3.7-plus",
    max_tokens: 1024,
    stream: true,
    messages: [{
      role: "user",
      content: "Give a brief introduction to artificial intelligence."
    }],
    thinking: { type: "disabled" },
  });

  for await (const chunk of stream) {
    if (chunk.type === "content_block_delta" && 'text' in chunk.delta) {
      process.stdout.write(chunk.delta.text);
    }
  }
}

main().catch(console.error);

curl

curl -X POST "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic/v1/messages" \
  -H "Content-Type: application/json" \
  -H "x-api-key: $DASHSCOPE_API_KEY" \
  --no-buffer \
  -d '{
    "model": "qwen3.7-plus",
    "max_tokens": 1024,
    "stream": true,
    "messages": [
        {
            "role": "user",
            "content": "Give a brief introduction to artificial intelligence."
        }
    ],
    "thinking": {"type": "disabled"}
}'

拡張思考

Python

import anthropic
import os

client = anthropic.Anthropic(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # {WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
)

stream = client.messages.create(
    model="qwen3.7-plus",
    max_tokens=2048,
    stream=True,
    thinking={
        "type": "enabled",
        "budget_tokens": 1024
    },
    messages=[
        {
            "role": "user",
            "content": "Analyze the future prospects of quantum computing."
        }
    ]
)

for chunk in stream:
    if chunk.type == "content_block_delta":
        if hasattr(chunk.delta, 'thinking'):
            print(chunk.delta.thinking, end="", flush=True)
        elif hasattr(chunk.delta, 'text'):
            print(chunk.delta.text, end="", flush=True)

TypeScript

import Anthropic from "@anthropic-ai/sdk";

async function main() {
  const anthropic = new Anthropic({
    apiKey: process.env.DASHSCOPE_API_KEY,
    // {WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
  });

  const stream = await anthropic.messages.create({
    model: "qwen3.7-plus",
    max_tokens: 2048,
    stream: true,
    thinking: { type: "enabled", budget_tokens: 1024 },
    messages: [{
      role: "user",
      content: "Analyze the future prospects of quantum computing."
    }]
  });

  for await (const chunk of stream) {
    if (chunk.type === "content_block_delta") {
      if ('thinking' in chunk.delta) {
        process.stdout.write(chunk.delta.thinking);
      } else if ('text' in chunk.delta) {
        process.stdout.write(chunk.delta.text);
      }
    }
  }
}

main().catch(console.error);

curl

curl -X POST "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic/v1/messages" \
  -H "Content-Type: application/json" \
  -H "x-api-key: $DASHSCOPE_API_KEY" \
  -d '{
    "model": "qwen3.7-plus",
    "max_tokens": 2048,
    "stream": true,
    "thinking": {
        "type": "enabled",
        "budget_tokens": 1024
    },
    "messages": [
        {
            "role": "user",
            "content": "Analyze the future prospects of quantum computing."
        }
    ]
}'

画像認識

Python

import anthropic
import os

client = anthropic.Anthropic(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # {WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
)

stream = client.messages.create(
    model="qwen3.7-plus",
    max_tokens=1024,
    stream=True,
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "image",
                    "source": {
                        "type": "url",
                        "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20250414/mqqmiy/animal_01.jpg",
                    },
                },
                {
                    "type": "text",
                    "text": "Describe the content of this image."
                },
            ],
        }
    ],
    thinking={"type": "disabled"},
)

for chunk in stream:
    if chunk.type == "content_block_delta":
        if hasattr(chunk.delta, 'text'):
            print(chunk.delta.text, end="", flush=True)

TypeScript

import Anthropic from "@anthropic-ai/sdk";

async function main() {
  const anthropic = new Anthropic({
    apiKey: process.env.DASHSCOPE_API_KEY,
    // {WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
  });

  const stream = await anthropic.messages.create({
    model: "qwen3.7-plus",
    max_tokens: 1024,
    stream: true,
    messages: [{
      role: "user",
      content: [
        {
          type: "image",
          source: {
            type: "url",
            url: "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20250414/mqqmiy/animal_01.jpg",
          },
        },
        { type: "text", text: "Describe the content of this image." },
      ],
    }],
    thinking: { type: "disabled" },
  });

  for await (const chunk of stream) {
    if (chunk.type === "content_block_delta" && 'text' in chunk.delta) {
      process.stdout.write(chunk.delta.text);
    }
  }
}

main().catch(console.error);

curl

curl -X POST "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic/v1/messages" \
  -H "Content-Type: application/json" \
  -H "x-api-key: $DASHSCOPE_API_KEY" \
  -d '{
    "model": "qwen3.7-plus",
    "max_tokens": 1024,
    "stream": true,
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "image",
                    "source": {
                        "type": "url",
                        "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250414/mqqmiy/animal_01.jpg"
                    }
                },
                {
                    "type": "text",
                    "text": "このイメージの内容を説明してください。"
                }
            ]
        }
    ],
    "thinking": {"type": "disabled"}
}'

動画認識

Python

import anthropic
import os

client = anthropic.Anthropic(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # {WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
)

stream = client.messages.create(
    model="qwen3.7-plus",
    max_tokens=1024,
    stream=True,
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "video",
                    "source": {
                        "type": "url",
                        "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20251208/zpupby/3e81ef38-98f0-4d55-bbb6-259334ca18d0.mp4",
                    },
                },
                {
                    "type": "text",
                    "text": "Describe the content of this video."
                },
            ],
        }
    ],
    thinking={"type": "disabled"},
)

for chunk in stream:
    if chunk.type == "content_block_delta":
        if hasattr(chunk.delta, 'text'):
            print(chunk.delta.text, end="", flush=True)

TypeScript

import Anthropic from "@anthropic-ai/sdk";

async function main() {
  const anthropic = new Anthropic({
    apiKey: process.env.DASHSCOPE_API_KEY,
    // {WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
  });

  const stream = await anthropic.messages.create({
    model: "qwen3.7-plus",
    max_tokens: 1024,
    stream: true,
    messages: [{
      role: "user",
      content: [
        {
          type: "video",
          source: {
            type: "url",
            url: "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20251208/zpupby/3e81ef38-98f0-4d55-bbb6-259334ca18d0.mp4",
          },
        },
        { type: "text", text: "Describe the content of this video." },
      ],
    }],
    thinking: { type: "disabled" },
  });

  for await (const chunk of stream) {
    if (chunk.type === "content_block_delta" && 'text' in chunk.delta) {
      process.stdout.write(chunk.delta.text);
    }
  }
}

main().catch(console.error);

curl

curl -X POST "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic/v1/messages" \
  -H "Content-Type: application/json" \
  -H "x-api-key: $DASHSCOPE_API_KEY" \
  -d '{
    "model": "qwen3.7-plus",
    "max_tokens": 1024,
    "stream": true,
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "video",
                    "source": {
                        "type": "url",
                        "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251208/zpupby/3e81ef38-98f0-4d55-bbb6-259334ca18d0.mp4"
                    }
                },
                {
                    "type": "text",
                    "text": "このビデオの内容を説明してください。"
                }
            ]
        }
    ],
    "thinking": {"type": "disabled"}
}'

関数呼び出し

Python

import anthropic
import os

client = anthropic.Anthropic(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # {WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
)

tools = [
    {
        "name": "get_weather",
        "description": "Get weather information for a specified city",
        "input_schema": {
            "type": "object",
            "properties": {
                "city": {
                    "type": "string",
                    "description": "City name"
                }
            },
            "required": ["city"]
        }
    }
]

message = client.messages.create(
    model="qwen3.7-plus",
    max_tokens=1024,
    tools=tools,
    messages=[
        {
            "role": "user",
            "content": "What's the weather like in Hangzhou today?"
        }
    ]
)

print(message.content)

TypeScript

import Anthropic from "@anthropic-ai/sdk";

async function main() {
  const anthropic = new Anthropic({
    apiKey: process.env.DASHSCOPE_API_KEY,
    // {WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
  });

  const message = await anthropic.messages.create({
    model: "qwen3.7-plus",
    max_tokens: 1024,
    tools: [
      {
        name: "get_weather",
        description: "Get weather information for a specified city",
        input_schema: {
          type: "object",
          properties: {
            city: { type: "string", description: "City name" }
          },
          required: ["city"],
        },
      },
    ],
    messages: [{
      role: "user",
      content: "What's the weather like in Hangzhou today?"
    }],
  });

  console.log(JSON.stringify(message.content, null, 2));
}

main().catch(console.error);

curl

curl -X POST "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic/v1/messages" \
  -H "Content-Type: application/json" \
  -H "x-api-key: $DASHSCOPE_API_KEY" \
  -d '{
    "model": "qwen3.7-plus",
    "max_tokens": 1024,
    "tools": [
        {
            "name": "get_weather",
            "description": "Get weather information for a specified city",
            "input_schema": {
                "type": "object",
                "properties": {
                    "city": {
                        "type": "string",
                        "description": "City name"
                    }
                },
                "required": ["city"]
            }
        }
    ],
    "messages": [
        {
            "role": "user",
            "content": "What's the weather like in Hangzhou today?"
        }
    ]
}'

プロンプトキャッシュ

Python

import anthropic
import os

client = anthropic.Anthropic(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # {WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
)

# コードリポジトリのコンテンツをシミュレートします。キャッシュ可能な最小長 (1024 トークン) に達する必要があります
long_text_content = "<Your Code Here>" * 400


def get_completion(user_input):
    response = client.messages.create(
        # プロンプトキャッシュをサポートするモデルを選択します
        model="qwen3.7-plus",
        max_tokens=1024,
        system=[
            {
                "type": "text",
                "text": long_text_content,
                # テキストブロックに cache_control を追加して、キャッシュのブレークポイントをマークします。messages 配列のコンテンツブロックにも配置できます
                "cache_control": {"type": "ephemeral"},
            }
        ],
        messages=[
            {"role": "user", "content": user_input},
        ],
    )
    return response


# 最初のリクエスト:キャッシュを作成
first = get_completion("What does this code do?")
print(f"Cache creation tokens: {first.usage.cache_creation_input_tokens}")
print(f"Cache read tokens: {first.usage.cache_read_input_tokens}")
print("=" * 20)
# 2 番目のリクエスト:同じ長いコンテンツ、異なる質問 -> キャッシュヒット
second = get_completion("How can this code be optimized?")
print(f"Cache creation tokens: {second.usage.cache_creation_input_tokens}")
print(f"Cache read tokens: {second.usage.cache_read_input_tokens}")

TypeScript

import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  apiKey: process.env.DASHSCOPE_API_KEY,
  // {WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
  baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
});

// コードリポジトリのコンテンツをシミュレートします。キャッシュ可能な最小長 (1024 トークン) に達する必要があります
const longTextContent = "<Your Code Here>".repeat(400);

async function getCompletion(userInput) {
  return client.messages.create({
    // プロンプトキャッシュをサポートするモデルを選択します
    model: "qwen3.7-plus",
    max_tokens: 1024,
    system: [
      {
        type: "text",
        text: longTextContent,
        // テキストブロックに cache_control を追加して、キャッシュのブレークポイントをマークします。messages 配列のコンテンツブロックにも配置できます
        cache_control: { type: "ephemeral" },
      },
    ],
    messages: [{ role: "user", content: userInput }],
  });
}

// 最初のリクエスト:キャッシュを作成
const first = await getCompletion("What does this code do?");
console.log(`Cache creation tokens: ${first.usage.cache_creation_input_tokens}`);
console.log(`Cache read tokens: ${first.usage.cache_read_input_tokens}`);
console.log("=".repeat(20));
// 2 番目のリクエスト:同じ長いコンテンツ、異なる質問 -> キャッシュヒット
const second = await getCompletion("How can this code be optimized?");
console.log(`Cache creation tokens: ${second.usage.cache_creation_input_tokens}`);
console.log(`Cache read tokens: ${second.usage.cache_read_input_tokens}`);

curl

curl -X POST "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic/v1/messages" \
  -H "Content-Type: application/json" \
  -H "x-api-key: $DASHSCOPE_API_KEY" \
  -d '{
    "model": "qwen3.7-plus",
    "max_tokens": 1024,
    "system": [
      {
        "type": "text",
        "text": "<ここに 1024 トークン以上のキャッシュ可能なコンテンツを配置してください>",
        "cache_control": {"type": "ephemeral"}
      }
    ],
    "messages": [
      {"role": "user", "content": "What does this code do?"}
    ]
}'

構造化出力

Python

import anthropic
import os

client = anthropic.Anthropic(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # {WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
)

message = client.messages.create(
    model="deepseek-v4-pro",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": "このメールから主要な情報を抽出してください:田中一郎 (ichiro.tanaka@example.com) は Enterprise プランに興味があり、来週火曜日の午後 2 時にデモを希望しています。"
        }
    ],
    output_config={
        "format": {
            "type": "json_schema",
            "schema": {
                "type": "object",
                "properties": {
                    "name": {"type": "string"},
                    "email": {"type": "string"},
                    "plan_interest": {"type": "string"},
                    "demo_requested": {"type": "boolean"}
                },
                "required": ["name", "email", "plan_interest", "demo_requested"],
                "additionalProperties": False
            }
        }
    },
)

print(message.content[0].text)

TypeScript

import Anthropic from "@anthropic-ai/sdk";

const anthropic = new Anthropic({
  apiKey: process.env.DASHSCOPE_API_KEY,
  // {WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
  baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic",
});

async function main() {
  const message = await anthropic.messages.create({
    model: "deepseek-v4-pro",
    max_tokens: 1024,
    messages: [{
      role: "user",
      content: "このメールから主要な情報を抽出してください:田中一郎 (ichiro.tanaka@example.com) は Enterprise プランに興味があり、来週火曜日の午後 2 時にデモを希望しています。"
    }],
    output_config: {
      format: {
        type: "json_schema",
        schema: {
          type: "object",
          properties: {
            name: { type: "string" },
            email: { type: "string" },
            plan_interest: { type: "string" },
            demo_requested: { type: "boolean" }
          },
          required: ["name", "email", "plan_interest", "demo_requested"],
          additionalProperties: false
        }
      }
    }
  });

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

main().catch(console.error);

curl

curl -X POST "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic/v1/messages" \
  -H "Content-Type: application/json" \
  -H "x-api-key: $DASHSCOPE_API_KEY" \
  -d '{
    "model": "deepseek-v4-pro",
    "max_tokens": 1024,
    "messages": [
        {
            "role": "user",
            "content": "このメールから主要な情報を抽出してください: John Smith (john@example.com) はエンタープライズプランに興味があり、来週の火曜日の午後2時にデモのスケジュール設定を希望しています。"
        }
    ],
    "output_config": {
        "format": {
            "type": "json_schema",
            "schema": {
                "type": "object",
                "properties": {
                    "name": {"type": "string"},
                    "email": {"type": "string"},
                    "plan_interest": {"type": "string"},
                    "demo_requested": {"type": "boolean"}
                },
                "required": ["name", "email", "plan_interest", "demo_requested"],
                "additionalProperties": false
            }
        }
    }
}'

model string (必須)

モデル名。サポートされているモデル:

サポートされているモデル

Qwen-Max: qwen3.7-max, qwen3.7-max-2026-05-20, qwen3.7-max-2026-06-08, qwen3.6-max-preview, qwen3-max, qwen3-max-2026-01-23, qwen3-max-preview

Qwen-Plus: qwen3.7-plus, qwen3.7-plus-2026-05-26, qwen3.6-plus, qwen3.6-plus-2026-04-02, qwen3.5-plus, qwen3.5-plus-2026-04-20, qwen3.5-plus-2026-02-15, qwen-plus, qwen-plus-latest, qwen-plus-2025-09-11

Qwen-Flash: qwen3.6-flash, qwen3.6-flash-2026-04-16, qwen3.5-flash, qwen3.5-flash-2026-02-23, qwen-flash, qwen-flash-2025-07-28

Qwen-Turbo: qwen-turbo

Qwen-Coder: qwen3-coder-next, qwen3-coder-plus, qwen3-coder-plus-2025-09-23, qwen3-coder-flash

Qwen-VL: qwen3-vl-plus, qwen3-vl-flash, qwen-vl-max, qwen-vl-plus

Qwen オープンソースモデル: qwen3.6-27b, qwen3.5-397b-a17b, qwen3.5-122b-a10b, qwen3.5-27b, qwen3.5-35b-a3b

サードパーティモデル

deepseek-v4-pro, deepseek-v4-flash, kimi-k2.5, kimi-k2-thinking, glm-5.1, glm-5, glm-4.7, glm-4.6, MiniMax-M2.5, MiniMax-M2.1

max_tokens integer (必須)

返信コンテンツの最大トークン数。生成されたコンテンツがこの値を超えると、生成は早期に停止し、stop_reasonmax_tokens になります。

max_tokens は思考プロセスの長さを制限しません。拡張思考が有効な場合、思考トークンは thinking.budget_tokens によって別途制御されます。

system string または array (任意)

モデルの動作を定義するシステムプロンプト。system はトップレベルパラメーターであり、messages 配列は system ロールを受け付けません。

文字列は、単一の type="text" ブロックに相当します。配列を渡して、プロンプトキャッシュのブレークポイントをマークします。

プロパティ

type string (必須)

固定値:text

text string (必須)

システムプロンプトのテキスト。

cache_control object (任意)

プロンプトキャッシュのブレークポイント。キャッシュヒットした場合、後続のリクエストはキャッシュ読み取りレートで課金されます。type のみを含み、値は ephemeral に固定されます。

messages array (必須)

userassistant が交互に並んだメッセージ配列。

messages 配列要素

role string (必須)

メッセージのロール。有効な値:userassistant

content string または array (必須)

プレーンテキスト文字列または構造化コンテンツ配列。文字列は、type="text" の単一の content ブロックに相当します。

content 配列要素の型

テキスト

プロパティ

type string (必須)

固定値:text

text string (必須)

テキストコンテンツ。

cache_control object (任意)

プロンプトキャッシュのブレークポイント。type のみを含み、値は ephemeral に固定されます。

画像 (Vision モデルが必要)

プロパティ

type string (必須)

固定値:image

source object (必須)

画像データのソース。

プロパティ

type string (必須)

有効な値:url (パブリックイメージ URL)、base64 (Base64 エンコード)。

url string

typeurl の場合に必須となる、画像のパブリック URL。

media_type string

image/jpeg などの画像の MIME タイプ。typebase64 の場合に必須です。

data string

Base64 エンコードされた画像データ。typebase64 の場合に必須です。

動画 (Vision モデルが必要)

プロパティ

type string (必須)

固定値:video

source object (必須)

動画データのソース。

プロパティ

type string (必須)

有効な値:url (パブリック動画 URL)、base64 (Base64 エンコード)。

url string

typeurl の場合に必須となる、動画のパブリック URL。

media_type string

video/mp4 などの動画の MIME タイプ。typebase64 の場合に必須です。

data string

Base64 エンコードされた動画データ。typebase64 の場合に必須です。

ツール使用 (assistant ロール、モデルによって返されるツール呼び出し命令)

プロパティ

type string (必須)

固定値:tool_use

id string (必須)

ツール呼び出しの一意の識別子。後続の tool_result で結果を関連付けるために使用されます。

name string (必須)

呼び出されたツールの名前。

input object (必須)

ツール呼び出しの入力パラメーター。構造は、tools 内の対応するツールの input_schema によって決定されます。

cache_control object (任意)

プロンプトキャッシュのブレークポイント。type のみを含み、値は ephemeral に固定されます。ツール呼び出しのコンテンツはキャッシュプレフィックスに参加します。

ツール結果 (user ロール、モデルに返送されるツールの実行結果)

プロパティ

type string (必須)

固定値:tool_result

tool_use_id string (必須)

tool_use ブロックの id に対応します。

content string (必須)

ツールによって返されるコンテンツ。

cache_control object (任意)

プロンプトキャッシュのブレークポイント。type のみを含み、値は ephemeral に固定されます。

stream boolean (任意)

ストリーミングを有効にするかどうか。デフォルト値:false

temperature number (任意)

生成されるテキストの多様性を制御します。有効値の範囲:[0, 2)。値が大きいほど、よりランダムな結果が生成されます。

説明

この範囲は、公式の Anthropic の範囲 [0.0, 1.0] とは異なります。Anthropic から移行する際は、このパラメーターの値を確認してください。

top_p number (任意)

ニュークリアスサンプリングの確率のしきい値。

temperaturetop_p はどちらも生成されるテキストの多様性を制御できます。どちらか一方のみを設定することを推奨します。詳細については、「概要」をご参照ください。

top_k integer (任意)

サンプリング中の候補セットのサイズ。

stop_sequences array (任意)

生成を停止させるトリガーとなるテキストシーケンス。出力は、一致したシーケンスの前に終了します。

説明

一致後も、レスポンスの stop_reasonend_turn のままであり、レスポンスには一致したシーケンスは含まれません。

thinking object (任意)

拡張思考の構成。有効にすると、モデルは応答する前に推論を行い、レスポンスには thinking タイプのコンテンツブロックが含まれます。すべてのモデルが思考モードをサポートしているわけではありません。

プロパティ

type string (必須)

有効な値:enabled (思考モードを有効にする)、disabled (思考モードを無効にする)。

budget_tokens integer (任意)

思考プロセスの最大トークン数。max_tokens とは独立しています。このパラメーターは思考部分を制限し、max_tokens は最終的な返信を制限します。予算を大きくすると、複雑な質問に対してより徹底的な分析が可能になります。typeenabled の場合に有効です。

reasoning_effort string (任意)

モデルの推論の強度を制御します。有効な値:highmax。デフォルト値:max。サポートされているモデル:deepseek-v4-pro、deepseek-v4-flash。

説明

low または medium に設定すると high にマッピングされ、xhigh に設定すると max にマッピングされます。

tools array (任意)

関数呼び出しのためのツール定義。

tools 配列要素

name string (必須)

ツール名。

description string (任意)

ツール関数の説明。

input_schema object (必須)

ツール入力パラメーターの JSON スキーマ定義。

tool_choice object (任意)

ツール選択戦略:

  • {"type": "auto"}:モデルがツールを呼び出すかどうかを決定します (デフォルト)。

  • {"type": "any"}:モデルにいずれかのツールを強制的に呼び出させます。

  • {"type": "none"}:モデルによるツールの呼び出しを禁止します。

  • {"type": "tool", "name": "tool_name"}:モデルに指定されたツールを強制的に呼び出させます。

output_config object (任意)

構造化出力の構成。有効にすると、モデルは JSON 文字列を返します。動作はモデルによって異なります:

  • 厳密な構造化出力:deepseek および glm シリーズのモデルで利用可能です。モデルは提供された JSON スキーマに厳密に従い、同じフィールドタイプと階層を保証します。

  • 通常の構造化出力:他のすべてのモデルでは、スキーマフィールドの制約は適用されません。API は自動的にプレーン JSON モードにフォールバックします (出力が有効な JSON 文字列であることのみを保証)。このフォールバックモードでは、リクエストは次の両方を満たす必要があります:(1) output_config パラメーターが明示的に提供されていること、(2) system または messages のコンテンツにキーワード "JSON" (大文字と小文字を区別しない) が含まれていること。"JSON" キーワードがない場合、API は 'messages' must contain the word 'json' in some form というエラーをスローします。

プロパティ

format object (必須)

出力フォーマットの定義。

プロパティ

type string (必須)

固定値:json_schema

schema object (必須)

標準の JSON スキーマ仕様に従う JSON スキーマオブジェクト。type (データの型)、properties (フィールド定義)、required (必須フィールド名の配列)、および additionalProperties ( false に設定する必要があります) を含める必要があります。

非ストリーミングレスポンス

レスポンス例

{
  "id": "msg_e2898f19-fc0e-4cb3-bd9b-5b7dc4ea3bc9",
  "type": "message",
  "role": "assistant",
  "model": "qwen3.7-plus",
  "content": [
    {
      "type": "thinking",
      "thinking": "Let me analyze this problem...",
      "signature": ""
    },
    {
      "type": "text",
      "text": "Hello! I am Qwen..."
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 22,
    "output_tokens": 223,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0
  }
}

id string

一意のメッセージ識別子。

type string

固定値:message

role string

固定値:assistant

model string

生成に使用されたモデル。

content array

コンテンツ配列。

content 配列要素の型

テキスト

プロパティ

type string

固定値:text

text string

モデルによって生成されたテキストレスポンス。

思考 (拡張思考が有効な場合に返されます)

プロパティ

type string

固定値:thinking

thinking string

最終的なレスポンスの前のモデルの推論。

signature string

現在は空の文字列に固定されています。

ツール使用 (関数呼び出しシナリオ)

プロパティ

type string

固定値:tool_use

id string

一意のツール呼び出し識別子。tool_result と照合するために使用されます。

name string

呼び出されたツールの名前。

input object

ツール呼び出しの入力パラメーター。

stop_reason string

生成が停止した理由。有効な値:end_turn (正常完了)、max_tokens (トークン制限に到達)、tool_use (ツール呼び出し)。

stop_sequence string

常に null です。

usage object

トークン使用量の統計。

説明

ストリーミング呼び出しでは、message_start イベントの usage フィールドには input_tokensoutput_tokens のみが含まれます。4 つのフィールドすべては message_delta イベントで返されます。

プロパティ

input_tokens integer

入力トークン。

output_tokens integer

出力トークン。

cache_creation_input_tokens integer

キャッシュ作成で消費されたトークン。

cache_read_input_tokens integer

キャッシュ読み取りで消費されたトークン。

ストリーミングレスポンス

ストリーミングレスポンスの例

{"type":"message_start","message":{"id":"msg_xxx","type":"message","role":"assistant","model":"qwen3.7-plus","content":[],"usage":{"input_tokens":15,"output_tokens":0}}}
{"type":"content_block_start","index":0,"content_block":{"type":"thinking","thinking":"","signature":""}}
{"type":"content_block_delta","index":0,"delta":{"type":"thinking_delta","thinking":"Here's a thinking process:\n\n1. **Analyze User Input:**\n   - **Topic:** Artificial Intelligence (AI)\n   - **Request:** Give a brief introduction to artificial intelligence."}}
{"type":"content_block_delta","index":0,"delta":{"type":"signature_delta","signature":""}}
{"type":"content_block_stop","index":0}
{"type":"content_block_start","index":1,"content_block":{"type":"text","text":""}}
{"type":"content_block_delta","index":1,"delta":{"type":"text_delta","text":"Artificial intelligence (AI) is an important branch of computer science..."}}
{"type":"content_block_stop","index":1}
{"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":15,"output_tokens":1078,"cache_creation_input_tokens":0,"cache_read_input_tokens":0}}
{"type":"message_stop"}

message_start

最初のストリームイベントで、メッセージの開始を示します。

プロパティ

type string

固定値:message_start

message object

初期メッセージオブジェクト。content は空の配列で、usage には input_tokensoutput_tokens のみが含まれます。

content_block_start

コンテンツブロックの開始を示します。

プロパティ

type string

固定値:content_block_start

index integer

content 配列内の位置に対応する 0 から始まるインデックス。

content_block object

コンテンツブロックの初期オブジェクト。type の値は textthinking、または tool_use です。tool_use タイプの場合、このイベントでは input フィールドは空のオブジェクトであり、完全な入力パラメーターは後続の content_block_delta のデルタから組み立てられます。

content_block_delta

コンテンツブロックの増分更新。ブロックごとに複数のデルタが送信されます。

プロパティ

type string

固定値:content_block_delta

index integer

関連するコンテンツブロックのインデックス。

delta object

デルタオブジェクト。type の値:

  • text_delta:テキストデルタ。text フィールドを含みます。

  • thinking_delta:思考デルタ。thinking フィールドを含みます。

  • signature_delta:署名デルタ。signature フィールドを含みます (現在は空の文字列に固定)。

  • input_json_delta:ツール呼び出しの入力パラメーターデルタ。partial_json フィールドを含みます。

content_block_stop

コンテンツブロックの終了を示します。

プロパティ

type string

固定値:content_block_stop

index integer

終了したコンテンツブロックのインデックス。

message_delta

すべてのコンテンツブロックが終了した後に送信されます。停止理由と最終的なトークン使用量が含まれます。

プロパティ

type string

固定値:message_delta

delta object

stop_reasonstop_sequence を含みます。有効な値については、上記の非ストリーミングレスポンスの表をご参照ください。

usage object

input_tokensoutput_tokenscache_creation_input_tokenscache_read_input_tokens を含む、完全なトークン使用量の統計。

message_stop

最終イベントで、メッセージの終了を示します。

プロパティ

type string

固定値:message_stop

さらに、ストリーミングレスポンスは接続を維持するために定期的に ping イベント ({"type":"ping"}) を送信します。クライアントはこれらを無視できます。