伙伴带动大模型Tokens消耗埋点建议方案

更新时间:

为了扩大伙伴产品的销售,调动阿里云相关的销售资源,需统计伙伴每客户对大模型的Tokens的消耗。特提供本方案。依据本文档指导,伙伴在产品调用模型服务时需增加Header参数。

一、适用范围

  • 伙伴产品依赖在百炼构建的Agent/WorkFlow,或依赖百炼模型服务,消耗百炼Tokens。

  • 提供SaaSAPI类型产品,并在云市场上架的产品伙伴。

二、伙伴实施成本

  • 在系统调用百炼模型API时,增加Header参数(header : x-dashscope-euid ,大小写不敏感)。

  • 开发、测试相关总计耗时1-2天左右。

三、具体实施步骤

  • 伙伴调用百炼模型API,参考百炼模型官方API文档

  • API调用时,增加header : x-dashscope-euid (JSON格式,key大小写敏感、value大小写不敏感)

  • 联系对应PDM/PSA 确认埋点结果

x-dashscope-euid 格式说明:

考虑到系统扩展性,x-dashscope-euid 采用JSON格式传递。

JSON Scheme定义描述如下

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://example.com/product.schema.json",
  "title": "百炼模型调用Header参数x-dashscope-euid格式定义",
  "description": "百炼官方API时通过http header:x-dashscope-euid传入的euid对象",
  "type": "object",
  "properties": {
    "bizType": {
      "description": "业务类型,固定值为 'B2B'",
      "type": "string"
    },
    "moduleType": {
      "description": "模块类型,固定值为 'Third-partyproducts',代表伙伴产品",
      "type": "string"
    },
    "moduleCode": {
      "description": "模块编码,格式为 'market_${productCode}',其中 productCode 来源于云市场实例创建 SPI 回调参数",
      "type": "string"
    },
    "accountType": {
      "description": "账户类型,固定值为 'Aliyun'",
      "type": "string"
    },
    "accountId": {
      "description": "客户账号 ID,来源于云市场实例创建 SPI 回调参数中的 ${aliUid}",
      "type": "string"
    }
  },
  "required": [ "bizType", "moduleType", "moduleCode", "accountType", "accountId" ],
  "example": {
    "bizType": "B2B",
    "moduleType": "Third-partyproducts",
    "moduleCode": "market_abc123",
    "accountType": "Aliyun",
    "accountId": "1234567890"
  }
}

相关字段详细说明:

字段名

字段类型

字段描述

bizType

String

业务类型,固定值:B2B

moduleType

String

模块类型,固定值:Third-partyproducts,代表伙伴产品

moduleCode

String

模块编码,固定前缀为:market_,动态值${productCode},其中的productCode动态值来源于实例创建中的productCode参数值

accountType

String

客户的账号类型,固定值:Aliyun

accountId

String

客户的账号ID,动态值,来源于实例创建中的aliUid参数值

动态值获取说明:

  • 伙伴在云市场商品发布时,需要开启生产API通知功能,并填写相关的通知地址。具体可以参考发布SaaS商品发布API服务商品两个文档,示意图如下:image.png

在实际业务链路中,当客户购买云市场商品后,云市场会通过实例创建将上述所需的动态值传递给伙伴:

  • 伙伴需要记录相关信息,并在自己的业务系统中与客户身份绑定

  • 当客户在使用伙伴业务系统的AI能力时,通过header : x-dashscope-euid 将对应信息传递,平台会自动埋点并做相关统计。

动态时序说明:

  • 伙伴获取云市场动态信息时序图image

  • 伙伴调用百炼模型API 并传递Header参数示意图image

模型调用示例:

curl -X POST https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
-H 'x-dashscope-euid: {"bizType":"B2B", "moduleType":"Third-partyproducts", "moduleCode":"market_cmapi00069878", "accountType":"Aliyun", "accountId":"1288645010140669"}' \
-d '{
    "model": "qwen-plus",
    "messages": [
        {
            "role": "system",
            "content": "你是阿里云的产品专家,熟悉阿里云的各个产品."
        },
        {
            "role": "user", 
            "content": "阿里云百炼模型的API如何使用?"
        }
    ]
}'