リクエストボディ model string (必須)
モデル名。サポートされているモデル:
サポートされているモデル
Qwen-Max : qwen4-max、qwen3.8-max, qwen3.7-max, qwen3.7-max-2026-05-20, qwen3.7-max-2026-06-08
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-Flash : qwen3.8-flash, qwen3.7-flash, qwen3.7-flash-2026-07-15, 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-Coder : qwen3-coder-flash
Qwen-VL : qwen3-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-0731, kimi-k3.1-pro, kimi-k3, kimi-k2.7-code, kimi-k2.6, kimi-k2.5, glm-5.2, glm-5.1, glm-5, MiniMax-M2.5, deepseek-v4.1-flash-1017
max_tokens integer (必須)
qwen4-max、deepseek-v4-pro, deepseek-v4-flash-0731, qwen3.8-max, qwen3.8-flash: max_tokens は、応答コンテンツと Chain-of-Thought コンテンツの両方の最大合計トークン数です。モデルの出力がこの値を超えると、生成は早期に停止し、stop_reason は max_tokens になります。
max_tokens は、応答コンテンツと思考プロセスの合計の長さを制限します。拡張思考が有効な場合、max_tokens > thinking.budget_tokens
glm-5.2: thinking.budget_tokens パラメーターが渡されない場合、max_tokens は応答コンテンツと Chain-of-Thought コンテンツの両方の最大合計トークン数です。モデルの出力がこの値を超えると、生成は早期に停止し、stop_reason は max_tokens になります。thinking.budget_tokens パラメーターが渡される場合、max_tokens は応答コンテンツの最大トークン数のみであり、思考トークンは thinking.budget_tokens によって個別にコントロールされます。
その他のモデル:応答コンテンツの最大トークン数。生成されたコンテンツがこの値を超えると、生成は早期に停止し、stop_reason は max_tokens になります。
max_tokens は思考プロセスの長さを制限しません。拡張思考が有効な場合、思考トークンは thinking.budget_tokens によって個別にコントロールされます。
system string or array (任意)
モデルの動作を定義するシステムプロンプト。system はトップレベルパラメーターであり、messages 配列は system ロールを受け入れません。
文字列は、単一の type="text" ブロックに相当します。プロンプトキャッシュのブレークポイントをマークするには、配列を渡します。
プロパティ
type string (必須)
固定値:text。
text string (必須)
システムプロンプトのテキスト。
cache_control object (任意)
プロンプトキャッシュのブレークポイント。キャッシュヒット時、後続のリクエストはキャッシュ読み取りレートで請求されます。type のみを含み、ephemeral に固定されます。
プロパティ(Qwen4)
qwen4-max と のみ対応します。 Qwen4 のコンテンツブロックのキャッシュマーカーは ttl にも対応します。5m または 1h、既定値は 5m です。 明示的キャッシュ(Qwen4) を参照してください。
type string (必須)
ephemeral
ttl string (任意)
キャッシュ TTL。5m または 1h。既定値は 5m。
messages array (必須)
user と assistant のターンが交互に並んだメッセージ配列。
messages 配列要素
role string (必須)
メッセージのロール。有効な値:user、assistant。
content string or array (必須)
プレーンテキスト文字列または構造化されたコンテンツ配列。文字列は、type="text" の単一の content ブロックに相当します。
content 配列要素の型
thinking (qwen4-max)
type string
thinking
thinking string
signature string
思考の要約と暗号化署名。後続のリクエストでは thinking ブロック全体をそのまま返します。
Text プロパティ
type string (必須)
固定値:text。
text string (必須)
テキストコンテンツ。
cache_control object (任意)
プロンプトキャッシュのブレークポイント。type のみを含み、ephemeral に固定されます。
プロパティ(Qwen4)
qwen4-max と のみ対応します。 Qwen4 のコンテンツブロックのキャッシュマーカーは ttl にも対応します。5m または 1h、既定値は 5m です。 明示的キャッシュ(Qwen4) を参照してください。
type string (必須)
ephemeral
ttl string (任意)
キャッシュ TTL。5m または 1h。既定値は 5m。
document (qwen4-max)
type string (必須)
固定値:document。
source object (必須)
イメージデータのソース。
プロパティ
type string (必須)
base64
media_type string
イメージの MIME タイプ (例:application/pdf)。type が base64 の場合に必須です。
data string
Base64 エンコードされたイメージデータ。type が base64 の場合に必須です。
Image (Vision モデルが必要)
プロパティ
type string (必須)
固定値:image。
source object (必須)
イメージデータのソース。
プロパティ
type string (必須)
有効な値:url (パブリックイメージ URL)、base64 (Base64 エンコード)。
url string
イメージのパブリック URL。type が url の場合に必須です。
media_type string
イメージの MIME タイプ (例:image/jpeg)。type が base64 の場合に必須です。
data string
Base64 エンコードされたイメージデータ。type が base64 の場合に必須です。
Video (Vision モデルが必要)
プロパティ
type string (必須)
固定値:video。
source object (必須)
ビデオデータのソース。
プロパティ
type string (必須)
有効な値:url (パブリックビデオ URL)、base64 (Base64 エンコード)。
url string
ビデオのパブリック URL。type が url の場合に必須です。
media_type string
ビデオの MIME タイプ (例:video/mp4)。type が base64 の場合に必須です。
data string
Base64 エンコードされたビデオデータ。type が base64 の場合に必須です。
PDF ドキュメント qwen3.8-max、qwen3.8-flash、および qwen4 シリーズのモデルは、Anthropic 互換 Messages API で PDF ファイルの URL 入力に対応しています。messages[].content で type: "document" のコンテンツブロックを使用し、source.type を url に設定して、source.url に PDF ファイルの URL を指定します。
URL 入力では、type は必須で値は document です。source は必須のオブジェクトです。その中の type は必須の文字列で url に設定し、url は PDF ファイルの URL を指定する必須の文字列です。
この例ではシンガポールリージョンを使用します。{WorkspaceId} をワークスペース ID に置き換え、環境変数 DASHSCOPE_API_KEY に Model Studio の API キーを設定してください。
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/apps/anthropic/v1/messages' \
--header 'Content-Type: application/json' \
--header "x-api-key: $DASHSCOPE_API_KEY" \
--data '{
"model": "qwen3.8-max",
"max_tokens": 1024,
"messages": [{
"role": "user",
"content": [
{
"type": "document",
"source": {
"type": "url",
"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260616/qmycjl/1506.02640v5.pdf"
}
},
{"type": "text", "text": "总结一下这个PDF文档的内容"}
]
}]
}'
PDF 理解
Tool use (assistant ロール、モデルによって返されるツール呼び出し命令)
プロパティ
type string (必須)
固定値:tool_use。
id string (必須)
ツール呼び出しの一意の識別子。後続の tool_result で結果を関連付けるために使用されます。
name string (必須)
呼び出されたツールの名前。
input object (必須)
ツール呼び出しの入力パラメーター。構造は、tools 内の対応するツールの input_schema によって決定されます。
cache_control object (任意)
プロンプトキャッシュのブレークポイント。type のみを含み、ephemeral に固定されます。ツール呼び出しのコンテンツはキャッシュプレフィックスに含まれます。
プロパティ(Qwen4)
qwen4-max と のみ対応します。 Qwen4 のコンテンツブロックのキャッシュマーカーは ttl にも対応します。5m または 1h、既定値は 5m です。 明示的キャッシュ(Qwen4) を参照してください。
type string (必須)
ephemeral
ttl string (任意)
キャッシュ TTL。5m または 1h。既定値は 5m。
Tool result (user ロール、モデルに返送されるツールの実行結果)
プロパティ
type string (必須)
固定値:tool_result。
tool_use_id string (必須)
tool_use ブロックの id に対応します。
content string (必須)
ツールによって返されたコンテンツ。
cache_control object (任意)
プロンプトキャッシュのブレークポイント。type のみを含み、ephemeral に固定されています。
プロパティ(Qwen4)
qwen4-max と のみ対応します。 Qwen4 のコンテンツブロックのキャッシュマーカーは ttl にも対応します。5m または 1h、既定値は 5m です。 明示的キャッシュ(Qwen4) を参照してください。
type string (必須)
ephemeral
ttl string (任意)
キャッシュ TTL。5m または 1h。既定値は 5m。
cache_control object (任意)
qwen4-max と のみ対応します。 リクエスト直下で自動キャッシュを有効にします。コンテンツブロックに手動のブレークポイントも設定できます。type は ephemeral 固定です。 非標準の最上位パラメーターは Python SDK の extra_body で渡します。Node.js SDK と curl では直接渡します。 明示的キャッシュ(Qwen4) を参照してください。
プロパティ
type string (必須)
ephemeral
ttl string (任意)
キャッシュ TTL。5m または 1h。既定値は 5m。
stream boolean (任意)
ストリーミングを有効にするかどうか。デフォルト値:false。
temperature number (任意)
生成されるテキストの多様性をコントロールします。有効値:[0, 2)。値が大きいほど、よりランダムな結果が生成されます。
注記 この有効値は、公式の Anthropic の有効値 [0.0, 1.0] とは異なります。Anthropic から移行する際は、このパラメーターの値を確認してください。
top_p number (任意)
Nucleus サンプリングの確率しきい値。
temperature と top_p はどちらも生成されるテキストの多様性をコントロールできます。どちらか一方のみを設定することを推奨します。詳細については、「概要 」をご参照ください。
top_k integer (任意)
サンプリング中の候補セットのサイズ。
stop_sequences array (任意)
生成を停止させるトリガーとなるテキストシーケンス。出力は一致したシーケンスの前に終了します。
注記 一致後、応答の stop_reason は end_turn のままであり、応答には一致したシーケンスは含まれません。
thinking object (任意)
kimi-k3.1-pro はデフォルトで思考が有効です。
拡張思考の構成。有効にすると、モデルは応答する前に推論を行い、応答には thinking タイプのコンテンツブロックが含まれます。すべてのモデルが思考モードをサポートしているわけではありません。
このパラメーターが渡されない場合、思考が実行されるかどうかはモデルのデフォルトの動作で決まります:qwen4-max、qwen3.8-max、qwen3.8-flash、deepseek-v4 シリーズ、glm シリーズ、kimi-k3.1-pro はデフォルトで思考が有効、kimi-k2.6 と kimi-k2.5 はデフォルトで思考が無効、kimi-k2.7-code と MiniMax-M2.5 は思考モードのみサポート (無効化できません)。各モデルの思考モードのサポート状況とデフォルト設定については、ディープシンキング をご参照ください。
プロパティ
type string (必須)
有効な値:enabled (思考モードを有効にする)、disabled (思考モードを無効にする)。
budget_tokens integer (任意)
思考プロセスの最大トークン数。max_tokens との関係はモデルによって異なります。詳しくは max_tokens パラメーターの説明をご参照ください。予算が大きいほど、複雑な質問に対してより徹底的な分析が可能になります。type が enabled の場合に有効です。
display string (任意)
qwen4-max: "summarized". 思考の要約と暗号化 .
デフォルトでは完全な思考を返します。有効にすると元の思考は平文では返されず、表示用の要約と履歴の復元用の完全な暗号文を返します。
tools array (任意)
関数呼び出しのためのツール定義。
kimi-k3.1-pro (Alibaba Cloud Model Studio にデプロイ) は、北京、シンガポール、米国 (バージニア)、ドイツ (フランクフルト)、日本 (東京)、中国 (香港) で、web_search と web_fetch をサポートします。
deepseek-v4.1-flash-1017 は、ウェブ検索ツール web_search とウェブ取得ツール web_fetch をサポートします。Anthropic 互換リクエストの要件と例については、ウェブ抽出 をご参照ください。
qwen4-max: web_search, web_fetch.
tools に名前が web_fetch のツールを追加し、同じリクエストに名前が web_search のツールも追加します。エンドポイントは https://{WorkspaceId}.{region}.maas.aliyuncs.com/apps/anthropic です。
web_fetch (qwen4-max)
type string
web_fetch_20250910
name string
web_fetch
max_uses integer
tool_choice object (任意)
ツール選択戦略:
{"type": "auto"}:モデルがツールを呼び出すかどうかを決定します (デフォルト)。
{"type": "any"}:モデルにいずれかのツールを強制的に呼び出させます。
{"type": "none"}:モデルがツールを呼び出すことを禁止します。
{"type": "tool", "name": "tool_name"}:モデルに指定されたツールを強制的に呼び出させます。
output_config object (任意)
プロパティ
effort string (任意)
qwen4-max
選択可能な値は low、high(デフォルト)、xhigh です。
medium は high に、max は xhigh にマッピングされます。
モデルの推論の強度をコントロールします。有効な値とデフォルト値はモデルによって異なります。デフォルト値:max。
kimi-k3.1-pro (Alibaba Cloud Model Studio にデプロイ) のデフォルトは max です。max (深い推論)、high (強化された推論)、medium (中程度の推論)、low (軽い推論) をサポートします。
以下は既存モデルの設定です。
有効な値:
low と medium は high に、xhigh は max にマッピングされます。
サポートされているモデル:glm-5.2、deepseek-v4-pro。
format object (任意)
構造化出力の構成。有効にすると、モデルは JSON 文字列を返します。動作はモデルによって異なります。
厳密な構造化出力 :deepseek (deepseek-v4-flash-0731、deepseek-v4-pro-0813 を除く) および glm シリーズのモデルで利用可能です。モデルは提供された JSON スキーマに厳密に従い、同じフィールドタイプと階層を保証します。
通常の構造化出力 :他のすべてのモデルでは、スキーマフィールドの制約は強制されません。API は自動的にプレーンな JSON モード (出力が有効な JSON 文字列であることを保証するのみ) にフォールバックします。このフォールバックモードでは、リクエストは次の両方を満たす必要があります:(1) output_config パラメーターが明示的に提供されていること、(2) system または messages のコンテンツにキーワード「JSON」(大文字と小文字を区別しない) が含まれていること。キーワード「JSON」がない場合、API は 'messages' must contain the word 'json' in some form というエラーをスローします。
プロパティ
type string (必須)
固定値:json_schema。
schema object (必須)
標準の JSON スキーマ仕様に従う JSON スキーマオブジェクト。type (データの型)、properties (フィールド定義)、required (必須フィールド名の配列)、および additionalProperties ( false に設定する必要があります) を含める必要があります。
基本的な呼び出し
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="qwen4-max",
max_tokens=1024,
system="You are a helpful assistant",
messages=[
{
"role": "user",
"content": "あなたは誰ですか?"
}
],
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: "qwen4-max",
max_tokens: 1024,
system: "You are a helpful assistant",
messages: [{
role: "user",
content: "あなたは誰ですか?"
}],
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": "qwen4-max",
"max_tokens": 1024,
"system": "You are a helpful assistant",
"messages": [
{
"role": "user",
"content": "あなたは誰ですか?"
}
],
"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="qwen4-max",
max_tokens=1024,
stream=True,
messages=[
{
"role": "user",
"content": "人工知能について簡単に紹介してください。"
}
],
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: "qwen4-max",
max_tokens: 1024,
stream: true,
messages: [{
role: "user",
content: "人工知能について簡単に紹介してください。"
}],
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": "qwen4-max",
"max_tokens": 1024,
"stream": true,
"messages": [
{
"role": "user",
"content": "人工知能について簡単に紹介してください。"
}
],
"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="qwen4-max",
max_tokens=2048,
stream=True,
thinking={
"type": "enabled",
"budget_tokens": 1024
},
messages=[
{
"role": "user",
"content": "量子コンピューティングの将来性について分析してください。"
}
]
)
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: "qwen4-max",
max_tokens: 2048,
stream: true,
thinking: { type: "enabled", budget_tokens: 1024 },
messages: [{
role: "user",
content: "量子コンピューティングの将来性について分析してください。"
}]
});
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": "qwen4-max",
"max_tokens": 2048,
"stream": true,
"thinking": {
"type": "enabled",
"budget_tokens": 1024
},
"messages": [
{
"role": "user",
"content": "量子コンピューティングの将来性について分析してください。"
}
]
}'
画像認識
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="qwen4-max",
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"},
)
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: "qwen4-max",
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" },
});
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": "qwen4-max",
"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="qwen4-max",
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"},
)
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: "qwen4-max",
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" },
});
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": "qwen4-max",
"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": "指定された都市の天気情報を取得します",
"input_schema": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "都市名"
}
},
"required": ["city"]
}
}
]
message = client.messages.create(
model="qwen4-max",
max_tokens=1024,
tools=tools,
messages=[
{
"role": "user",
"content": "今日の杭州の天気はどうですか?"
}
]
)
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: "qwen4-max",
max_tokens: 1024,
tools: [
{
name: "get_weather",
description: "指定された都市の天気情報を取得します",
input_schema: {
type: "object",
properties: {
city: { type: "string", description: "都市名" }
},
required: ["city"],
},
},
],
messages: [{
role: "user",
content: "今日の杭州の天気はどうですか?"
}],
});
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": "qwen4-max",
"max_tokens": 1024,
"tools": [
{
"name": "get_weather",
"description": "指定された都市の天気情報を取得します",
"input_schema": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "都市名"
}
},
"required": ["city"]
}
}
],
"messages": [
{
"role": "user",
"content": "今日の杭州の天気はどうですか?"
}
]
}'
プロンプトキャッシュ
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="qwen4-max",
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("このコードは何をしますか?")
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("このコードはどのように最適化できますか?")
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: "qwen4-max",
max_tokens: 1024,
system: [
{
type: "text",
text: longTextContent,
// テキストブロックに cache_control を追加して、キャッシュのブレークポイントをマークします。messages 配列のコンテンツブロックにも配置できます
cache_control: { type: "ephemeral" },
},
],
messages: [{ role: "user", content: userInput }],
});
}
// 最初のリクエスト:キャッシュを作成
const first = await getCompletion("このコードは何をしますか?");
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("このコードはどのように最適化できますか?");
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": "qwen4-max",
"max_tokens": 1024,
"system": [
{
"type": "text",
"text": "<ここに少なくとも 1024 トークンのキャッシュ可能なコンテンツを配置します>",
"cache_control": {"type": "ephemeral"}
}
],
"messages": [
{"role": "user", "content": "このコードは何をしますか?"}
]
}'
構造化出力
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": "次のメールから重要な情報を抽出してください:田中一郎 (tanaka@example.com) は Enterprise プランに興味があり、来週火曜日の午後2時にデモを希望しています。"
}
],
extra_body={
"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
}
}
}
},
)
# deepseek-v4-pro は thinking ブロックを返すため、text コンテンツブロックを見つけます
text_block = next(block for block in message.content if block.type == "text")
print(text_block.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() {
// output_config は Model Studio プラットフォームの拡張パラメーターであり、ボディ経由で渡します
const message = await (anthropic.messages.create as Function)({
model: "deepseek-v4-pro",
max_tokens: 1024,
messages: [{
role: "user",
content: "次のメールから重要な情報を抽出してください:田中一郎 (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
}
}
}
});
// deepseek-v4-pro は thinking ブロックを返すため、text コンテンツブロックを見つけます
const textBlock = message.content.find(
(block: { type: string }) => block.type === "text"
);
console.log(textBlock?.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": "次のメールから重要な情報を抽出してください:田中一郎 (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
}
}
}
}'