蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

在本机检查端点、协议和凭据归属

PYTHONCPython 3.12,离线模拟配置检查。厂商账户与扣费由控制台验证。plan_check.py
plan_check.py57 行
"""Check teaching profiles against the documented plan and protocol endpoints."""
from dataclasses import dataclass
import json

ARK = "https://ark.cn-beijing.volces.com/api/coding"
ALI = "https://coding.dashscope.aliyuncs.com"
TOKEN = "https://token-plan.cn-beijing.maas.aliyuncs.com"
ARK_USAGE = "https://ark.cn-beijing.volces.com/api/v3"

ENDPOINTS = {
    ("ark-plan", "anthropic"): ARK,
    ("ark-plan", "openai"): ARK + "/v3",
    ("ali-coding", "anthropic"): ALI + "/apps/anthropic",
    ("ali-coding", "openai"): ALI + "/v1",
    ("ali-token-beijing", "anthropic"): TOKEN + "/apps/anthropic",
    ("ali-token-beijing", "openai"): TOKEN + "/compatible-mode/v1",
}


@dataclass(frozen=True)
class Profile:
    product: str
    protocol: str
    endpoint: str
    credential_product: str
    model: str

    def validate(self):
        expected = ENDPOINTS.get((self.product, self.protocol))
        if expected is None:
            raise ValueError("unsupported profile")
        if self.endpoint == ARK_USAGE:
            raise ValueError("pay-as-you-go endpoint")
        if self.endpoint != expected:
            raise ValueError("endpoint does not match product and protocol")
        if self.credential_product != self.product:
            raise ValueError("credential belongs to another product")
        if not self.model.strip():
            raise ValueError("missing model")
        suffix = "/v1/messages" if self.protocol == "anthropic" else "/chat/completions"
        return self.endpoint + suffix

    def settings(self):
        self.validate()
        if self.protocol != "anthropic":
            raise ValueError("choose an Anthropic profile for Claude Code")
        return {"env": {"ANTHROPIC_BASE_URL": self.endpoint, "ANTHROPIC_MODEL": self.model}}


def main():
    profile = Profile("ark-plan","anthropic",ARK,"ark-plan","ark-code-latest")
    print(json.dumps({"request_url": profile.validate(), "settings": profile.settings()},indent=2))


if __name__=="__main__":
    main()
本例需在 CPython 3.12,离线模拟配置检查。厂商账户与扣费由控制台验证。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程

运行环境:CPython 3.12,离线模拟配置检查。厂商账户与扣费由控制台验证。

入口文件:projects/claude-code-plan-and-first-use/plan_check.py

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 plan_check.py,或下载右侧课程工程包。
  2. 确认本地已准备 CPython 3.12,离线模拟配置检查。厂商账户与扣费由控制台验证。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:Claude Code

课程关联工程包(登记关联42章) · 含当前章节或实例 · mbskycom202612a3117.zip

下载课程关联工程包:Claude Code

课程关联工程包(登记关联2章) · 含当前章节或实例 · mbskycom202612a3139.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习