Files
2026-07-02 12:58:18 +08:00

57 lines
2.3 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Claude Code 接入
sidebarTitle: Claude Code
description: 在 Claude Code CLI 中对接自定义 APIOpenAI 兼容)
---
# Claude Code 接入
**Claude Code** 是面向终端的 AI 编程助手。不同版本对「自定义后端」的支持方式可能不同;海宇数科网关当前对外主要提供 **OpenAI Chat Completions 兼容** 接口(`https://api.haiyushuke.com/v1`**不提供** Anthropic 海外 Claude 原厂模型。
若你的 Claude Code 版本支持 **OpenAI 兼容 Base URL** 或可在配置中指定 OpenAI 风格端点,可按下列方式接入;若仅支持 Anthropic 原生 API则需改用 [Cursor](/docs/integrations/cursor)、[Continue](/docs/integrations/continue) 等工具,或通过业务后端自行调用 [HTTP API](/docs/guides/http_api)。
## 前置条件
- 控制台已 **实名认证**,已创建 **API Key**
- 已在 **模型广场** 选定国内模型 ID勿填海外 `claude-*` 名称)
## 配置思路OpenAI 兼容)
在 Claude Code 的环境变量或配置文件中(以官方文档为准),尝试设置与海宇网关等价的 OpenAI 兼容项,例如:
```bash
# 示例:名称以 Claude Code 当前版本文档为准
export OPENAI_API_KEY="YOUR_HAIYUSHUKE_API_KEY"
export OPENAI_BASE_URL="https://api.haiyushuke.com/v1"
```
将 **模型名** 设为控制台模型 ID例如
```bash
# 示例模型 ID请替换为模型广场实际值
export ANTHROPIC_MODEL="deepseek-chat"
```
> 部分 CLI 仍使用 `ANTHROPIC_*` 前缀命名环境变量,但后端实际走的是您配置的 Base URL请以 Claude Code 官方说明为准,并确认其请求是否落在 `/v1/chat/completions` 兼容路径上。
## 验证
1. 在控制台 **体验中心** 用同一模型 ID 发送一条消息
2. 在 Claude Code 中发起简单任务(如解释一个本地文件)
3. 在 **财务 → 使用记录** 查看是否产生对应调用
## 故障排查
| 现象 | 建议 |
| --- | --- |
| 401 | 检查 API Key、是否误用登录 token |
| 403 | Key 未授权该模型 ID或 IP 白名单限制 |
| 402 | 余额不足,前往充值 |
| 协议不匹配 | 换用 Cursor / Continue或直接用 HTTP/SDK 集成 |
## 相关文档
- [工具接入概览](/docs/integrations/overview)
- [Cursor 接入](/docs/integrations/cursor)
- [常见问题](/docs/faq)