Skip to content

Commit

Permalink
docs(readme): update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
UNICKCHENG committed Jul 16, 2023
1 parent d483e99 commit 1c86d6d
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 28 deletions.
Binary file added assets/8f0eedf67fcd0737026370624a8dfa8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/claude_org_id.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/claude_session.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
122 changes: 94 additions & 28 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@

API 文档请查看 👉 https://openai-proxy.apifox.cn

`openai-proxy` 是为中国用户提供的一个方案,即解决 openai api 无法正常请求。
`openai-proxy` 是为中国用户提供的一个方案,目前可以帮你解决的问题有:

现在您只需要将 `https://api.openai.com/` 替换成 `https://openai.aihey.cc/openai` 即可食用。
- ✅ OpenAI API 请求超时
- ✅ OpenAI API 不支持查询费用消耗量
- ✅ Claude API 还在等待列表中
- ✅ Google Bard 没有提供 API(目前存在问题,正在修复。。。)
- 。。。

## OpenAI API 请求超时

现在您只需要将 `https://api.openai.com` 替换成 `https://openai.aihey.cc/openai` 即可食用

```bash
# openai api
Expand All @@ -26,33 +34,11 @@ curl https://openai.aihey.cc/openai/v1/chat/completions \
}'
```

---

## ✨ 新特征

### 支持 Google Bard API(非官方)[目前存在问题]

> **承诺:当 Google Bard 官方开放 API 时,将替换为官方 API 请求**
借助 [PawanOsman/GoogleBard](https://github.com/PawanOsman/GoogleBard) 现成的封装,现支持通过 api 请求 Google Bard

```bash
curl https://openai.aihey.cc/google/bard \
-H "Content-Type: application/json" \
-d '{
"cookies": "__Secure-1PSID=**********************",
"prompt": "hello"
}'
```

> `__Secure-1PSID` 获取方式如下图,网页端打开 Google Bard 后,F12 查看 Cookies
> ![googlebard.png](assets/googlebard.png)
### 支持查询费用消耗量
## OpenAI API 不支持查询费用消耗量

> 自从 2023 年 04 月份开始,`https://api.openai.com/dashboard/billing/credit_grants` 只能通过网页登录生成的 session id 来请求,而 key (`sk-*****`) 的方式将无效。**不过您可以通过下述两个方式来请求**
> 自从 2023 年 04 月份开始,`https://api.openai.com/dashboard/billing/credit_grants` 只能通过网页登录生成的 session id 来请求,而 key (`sk-*****`) 的方式将无效。**不过您可以通过下述两个方式来请求**
#### 方式1:使用 `openai-proxy`
### 方式1:使用 `openai-proxy`

缺点:
- 可能和网页端显示的数据存在差异(这个不知道为啥,有了解的小伙伴欢迎在 [ISSUES](https://github.com/UNICKCHENG/openai-proxy/issues) 指出)
Expand All @@ -69,7 +55,7 @@ curl https://openai.aihey.cc/openai/billing/credit_grants \
-H "Authorization: Bearer sk-**********"
```

#### 方式2:使用网页端生成的 `sensitive_id`
### 方式2:使用网页端生成的 `sensitive_id`

缺点:
- 首次需要去网页端获取(按 F12 后刷新网页)
Expand All @@ -83,6 +69,82 @@ curl https://openai.aihey.cc/openai/billing/credit_grants\
-H "Authorization: Bearer sess-*****"
```

## Claude web API 支持

### 开始之前

- 访问 [claude.ai](https://claude.ai/) 创建账号(暂时只有美国和英国 IP 可访问)
- 从网页端拿到 orgId
- 从网页端拿到 sessionKey

> ![](assets/claude_org_id.png)
> ![](assets/claude_session.png)
### 获取全部会话

```bash
curl -X GET 'http://openai.aihey.cc/claude/organizations/dca2a902-a463-41f0-88cb-b047deb40178/chat_conversations' \
--header 'Accept: */*' \
--header 'Content-Type: application/json'
--header 'Cookie: sessionKey=sk-***********' \
```

### 生成 AI 回复
```bash
curl -X POST 'http://openai.aihey.cc/claude/append_message' \
--header 'Accept: text/event-stream' \
--header 'Cookie: sessionKey=sk-***********' \
--header 'Content-Type: application/json' \
--data-raw '{
"completion": {
"prompt": "hello",
"timezone": "Asia/Shanghai",
"model": "claude-2"
},
"organization_uuid": "dca2a902-a463-41f0-88cb-b047deb40178",
"conversation_uuid": "5446798e-0e11-4e8f-994c-3d8386f01bd6",
"text": "hello",
"attachments": []
}'
```

### 生成 AI 回复(类 OpenAI)

已经支持类似 gpt 的请求格式,如果你使用的第三方插件支持自定义 OpenAI 地址,现在可以直接将 `https://api.openai.com` 替换成 `http://openai.aihey.cc/claude/{organization_uuid}/{conversation_uuid}`

```bash
curl -X POST 'http://openai.aihey.cc/claude/dca2a902-a463-41f0-88cb-b047deb40178/5446798e-0e11-4e8f-994c-3d8386f01bd6/v1/chat/completions' \
--header 'Accept: */*' \
--header 'Content-Type: application/json' \
--data-raw '{
"model":"gpt-3.5-turbo",
"messages": [
{"role": "user", "content":"hello"}
],
"stream": false
}'
```

更多接口请参考 https://openai-proxy.apifox.cn/doc-2721086

### 支持 Google Bard API(非官方)[目前存在问题]

> **承诺:当 Google Bard 官方开放 API 时,将替换为官方 API 请求**
借助 [PawanOsman/GoogleBard](https://github.com/PawanOsman/GoogleBard) 现成的封装,现支持通过 api 请求 Google Bard

```bash
curl https://openai.aihey.cc/google/bard \
-H "Content-Type: application/json" \
-H "__Secure-1PSID=**********************"
-d '{
"prompt": "hello"
}'
```

> `__Secure-1PSID` 获取方式如下图,网页端打开 Google Bard 后,F12 查看 Cookies
> ![googlebard.png](assets/googlebard.png)
## 🎉 自行部署

#### step 1: 使用 vercel 部署
Expand Down Expand Up @@ -116,10 +178,14 @@ cname-china.vercel-dns.com
- 如果你是名爱折腾的开发者,或许也可以尝试 Nginx、Cloudflare 等方案
- 如果你希望有个直接拿来用的方案,那么请放心大胆地白嫖

![](8f0eedf67fcd0737026370624a8dfa8.jpg)


## 💖 感谢

- <https://vercel.com/docs>
- <https://nextjs.org/docs>
- <https://platform.openai.com/docs/api-reference>
- https://github.com/PawanOsman/GoogleBard
- https://github.com/vercel-labs/ai
- https://claude.ai

1 comment on commit 1c86d6d

@vercel
Copy link

@vercel vercel bot commented on 1c86d6d Jul 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.