Skip to main content

OpenCode

Alibaba Cloud Model Studio のモデルを OpenCode で使用します。

クイックスタート

  1. 1

    プロバイダーを接続する

    opencode を実行し、/connect を入力して、ご利用の課金プランに対応するプロバイダーを選択し、API キーを入力します:
    • Token Plan
    • 従量課金
    • Coding Plan
    Alibaba Token Plan (China) を選択し、エディションに対応する Token Plan API キーを入力します:
  2. 2

    モデルを選択する

    /models を入力し、使用するモデルを選択します。
  3. 3

    確認する

    次のコマンドを実行して確認します:
    opencode run "Hello"
    

設定ファイルで構成する

上記のオプションに加えて、設定ファイルを使用して接続することもできます。
  1. 1

    設定ファイルを開くか作成する

    • macOS / Linux: ~/.config/opencode/opencode.json
    • Windows: C:\Users\<username>\.config\opencode\opencode.json
  2. 2

    設定を記述する

    YOUR_API_KEY を、ご利用のプランの API キーに置き換えます。
    • Token Plan パーソナルエディション
    • Token Plan チームエディション
    • 従量課金
    • Coding Plan
    {
      "$schema": "https://opencode.ai/config.json",
      "provider": {
        "bailian-token-plan": {
          "npm": "@ai-sdk/anthropic",
          "name": "Alibaba Cloud Model Studio",
          "options": {
            "baseURL": "https://token-plan.ap-southeast-1.maas.aliyuncs.com/apps/anthropic/v1",
            "apiKey": "YOUR_API_KEY"
          },
          "models": {
            "auto": {
              "name": "Auto",
              "modalities": {
                "input": [
                  "text"
                ],
                "output": [
                  "text"
                ]
              },
              "limit": {
                "context": 1000000,
                "output": 393216
              }
            },
            "qwen4-max-preview": {
              "name": "Qwen4.0 Max Preview",
              "modalities": {
                "input": [
                  "text",
                  "image"
                ],
                "output": [
                  "text"
                ]
              },
              "limit": {
                "context": 1000000,
                "output": 131072
              }
            },
            "qwen3.8-max": {
              "name": "Qwen3.8 Max",
              "modalities": {
                "input": [
                  "text",
                  "image"
                ],
                "output": [
                  "text"
                ]
              },
              "limit": {
                "context": 1000000,
                "output": 131072
              }
            },
            "qwen3.8-flash": {
              "name": "Qwen3.8 Flash",
              "modalities": {
                "input": [
                  "text",
                  "image"
                ],
                "output": [
                  "text"
                ]
              },
              "limit": {
                "context": 1000000,
                "output": 131072
              }
            },
            "qwen3.7-max": {
              "name": "Qwen3.7 Max",
              "modalities": {
                "input": [
                  "text"
                ],
                "output": [
                  "text"
                ]
              },
              "limit": {
                "context": 1000000,
                "output": 65536
              }
            },
            "qwen3.7-plus": {
              "name": "Qwen3.7 Plus",
              "modalities": {
                "input": [
                  "text",
                  "image"
                ],
                "output": [
                  "text"
                ]
              },
              "limit": {
                "context": 1000000,
                "output": 65536
              }
            },
            "qwen3.6-flash": {
              "name": "Qwen3.6 Flash",
              "modalities": {
                "input": [
                  "text",
                  "image"
                ],
                "output": [
                  "text"
                ]
              },
              "limit": {
                "context": 1000000,
                "output": 65536
              }
            },
            "deepseek-v4.1-flash": {
              "name": "DeepSeek V4.1 Flash",
              "modalities": {
                "input": [
                  "text",
                  "image"
                ],
                "output": [
                  "text"
                ]
              },
              "limit": {
                "context": 1000000,
                "output": 65536
              }
            },
            "deepseek-v4.1-flash-1017": {
              "name": "DeepSeek V4.1 Flash 1017",
              "modalities": {
                "input": [
                  "text",
                  "image"
                ],
                "output": [
                  "text"
                ]
              },
              "limit": {
                "context": 1000000,
                "output": 65536
              }
            },
            "deepseek-v4-pro": {
              "name": "DeepSeek V4 Pro",
              "modalities": {
                "input": [
                  "text"
                ],
                "output": [
                  "text"
                ]
              },
              "limit": {
                "context": 1000000,
                "output": 65536
              }
            },
            "deepseek-v4-pro-0813": {
              "name": "DeepSeek V4 Pro 0813",
              "modalities": {
                "input": [
                  "text"
                ],
                "output": [
                  "text"
                ]
              },
              "limit": {
                "context": 1000000,
                "output": 65536
              }
            },
            "deepseek-v4-flash-0731": {
              "name": "DeepSeek V4 Flash 0731",
              "modalities": {
                "input": [
                  "text"
                ],
                "output": [
                  "text"
                ]
              },
              "limit": {
                "context": 1000000,
                "output": 65536
              }
            },
            "glm-5.3": {
              "name": "GLM-5.3",
              "modalities": {
                "input": [
                  "text"
                ],
                "output": [
                  "text"
                ]
              },
              "limit": {
                "context": 202752,
                "output": 16384
              }
            },
            "glm-5.2": {
              "name": "GLM-5.2",
              "modalities": {
                "input": [
                  "text"
                ],
                "output": [
                  "text"
                ]
              },
              "limit": {
                "context": 202752,
                "output": 16384
              }
            }
          }
        }
      }
    }
    
    qwen4-max-preview を使用する場合、1 回のリクエストあたりの出力上限はデフォルトで 32000 です。より長い出力が必要な場合は、OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX を設定します。

エラーコード

設定中にエラーが発生した場合は、ご利用の課金プランの FAQ ドキュメントを参照してください:

FAQ

従量課金の接続方法は変わりません。Model Studio の汎用 API Key と Base URL を使用します。節約プランを購入すると自動的に有効になり、対象の利用料金が自動的に控除されます。詳細は節約プランをご参照ください。
OpenCode を最新バージョンにアップグレードしてから、/models を再度確認してください。それでもモデルが見つからない場合は、opencode.json でカスタムプロバイダーを定義し、モデルを追加します。
API キーが選択したプロバイダーと一致していないか、キーが別の課金プランに属しています。/connect を再度実行し、ご利用のプランのプロバイダーを選択して、正しいキーを入力してください。