跳到主内容
Key 开通7 分钟阅读发布于:2026-07-29更新于:2026-07-29

如何获取 Claude API Key(2026 逐步指南)

Anthropic 的 Claude 是顶级 AI 模型。本文教你如何创建 Claude/Anthropic API Key、理解定价,并发送第一个 API 请求。

Claude API Key 和 Anthropic API Key 的区别

不存在单独的「Claude API Key」——你需要的实际上是 Anthropic API Key。Claude 是模型名,Anthropic 是提供 API 的公司。当你搜索「如何获取 Claude API Key」时,实际需要的是从 Anthropic Console 获取的 Anthropic API Key。

同一个 Key 可以用于所有 Claude 模型,包括 Claude Sonnet、Claude Opus 和 Claude Haiku。

第 1 步:注册 Anthropic 账号

前往 Anthropic Console(console.anthropic.com)注册。需要验证邮箱并提供手机号进行验证。

Anthropic 对大多数国家的开发者开放。如果你所在的地区 Anthropic 暂不直接可用,可能需要使用 VPN 或确认你的地区是否支持。

第 2 步:生成 API Key

登录 Anthropic Console 后,进入 API Keys 页面。点击「Create Key」,给 Key 起一个反映用途的名字(如「production-app」或「testing」),然后立即复制保存。

Anthropic 还支持工作区级别的 Key 管理,对团队很有用。你可以为不同的工作区或环境创建单独的 Key。

第 3 步:充值

Anthropic 采用预付费模式。在调用 API 之前需要先充值。新账号可能会获得少量免费测试额度。

进入控制台的 Billing 页面,添加支付方式并购买额度。你也可以设置消费上限以避免意外支出。

第 4 步:发送第一个请求

Anthropic 提供自己的 Python SDK。以下是调用 Claude 的最小示例:

python
import anthropic

client = anthropic.Anthropic(
    api_key="your-anthropic-api-key"
)

message = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Hello, what can you do?"}
    ]
)

print(message.content[0].text)

使用 Anthropic Python SDK 调用 Claude API 的最小示例

Claude API 定价

Anthropic 按百万 token 计费,输入和输出分别定价。不同 Claude 模型价格不同——Claude Haiku 最实惠,Claude Sonnet 中档,Claude Opus 是高端档。

建议查看 Anthropic 官方定价页面获取最新价格,因为新模型发布时定价可能会调整。

常见问题

Claude API Key 和 Anthropic API Key 是同一个吗?

是的。不存在单独的 Claude API Key。你在 Anthropic Console 创建的 Anthropic API Key 可以用于所有 Claude 模型。

Claude API 有免费额度吗?

新注册的 Anthropic 账号可能会获得少量免费测试额度。持续使用需要购买额度。没有像 Google AI Studio 那样的永久免费层。

可以用 OpenAI SDK 调用 Claude API 吗?

不能直接使用。Anthropic 有自己的 SDK。不过一些封装库和代理服务提供了 Claude 的 OpenAI 兼容接口。最佳实践是使用官方 Anthropic SDK。

相关供应商

参考来源