openai api key automatically rotating when deployed

题意:部署时自动轮换 OpenAI API 密钥

问题背景:

I'm building a web page using openai gpt API in reactjs. I saved my API key on .env file then gitignored it. And I deployed my code with gh-pages, but openai detects it and rotate the key automatically. How can I use API key properly?

我正在使用 ReactJS 构建一个网页,使用 OpenAI GPT API。我将 API 密钥保存在 .env 文件中,并将其添加到 .gitignore 中。然后我使用 gh-pages 部署了代码,但 OpenAI 检测到了这个密钥并自动轮换了它。我应该如何正确使用 API 密钥?

const DEFAULT_PARAMS = {
            model: "gpt-3.5-turbo",
            messages: [{"role": "user",
                        "content": message
            }],
            temperature: 1,
            max_tokens: 1000
        };
        const params_ = {...DEFAULT_PARAMS};
        const result = await fetch('https://api.openai.com/v1/chat/completions', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'Authorization': 'Bearer ' + String(process.env.REACT_APP_OPENAI_API_KEY)
            },
            body: JSON.stringify(params_)
        });
        const data = await result.json()

问题解决:

You can refer to this question regarding securing secrets on static websites hosted on GitHub Pages.

你可以参考这个问题,了解如何在 GitHub Pages 上托管的静态网站中保护秘密信息。

Short answer: it's impossible because everything is exposed in the code.

简短的回答:这是不可能的,因为代码中的所有内容都是公开的。

You need to use another way to deploy your website. For example, frameworks like NextJS.

你需要使用另一种方式来部署你的网站。例如,使用像 NextJS 这样的框架。

  • 7
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

营赢盈英

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值