You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在GCloud Vertex AI中为Anthropic模型API调用添加标签?

通过Anthropic Vertex SDK为请求添加自定义元数据标签

可行,具体操作如下:

  • 确认SDK版本
    确保你使用的@anthropic-ai/vertex-sdk版本在0.9.0及以上,该版本开始支持自定义标签参数。

  • 调用时添加labels参数
    在调用messages.create方法时,通过metadata字段下的labels属性传入键值对形式的自定义标签,示例代码如下:

import { AnthropicVertex } from '@anthropic-ai/vertex-sdk';

const client = new AnthropicVertex({
  region: 'your-gcp-region',
  projectId: 'your-gcp-project-id',
});

async function sendRequest() {
  const response = await client.messages.create({
    model: 'claude-3-opus@20240229',
    max_tokens: 1024,
    messages: [{ role: 'user', content: 'Hello, Claude!' }],
    // 添加自定义标签
    metadata: {
      labels: {
        "team": "engineering",
        "task_type": "chat_query",
        "environment": "production"
      }
    }
  });
  console.log(response);
}

sendRequest();
  • 验证标签生效
    标签会被关联到Vertex AI的请求日志和账单数据中,你可以在Google Cloud控制台的Vertex AI日志页面或账单导出数据中查看这些标签,用于成本分摊、请求分类等场景。

内容的提问来源于stack exchange,提问作者martin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 10:44:51