1. https://platform.openai.com/api-keys申请key,现在已经没有5美元的免费额度了,只能老老实实充钱
  2. https://platform.openai.com/usage可以看到api使用的情况
  3. 限制说明(如gpt-4o-mini):

macos终端代理不生效

  1. 本来希望使用curl测试一下(来源:https://platform.openai.com/docs/api-reference/making-requests

    curl <https://api.openai.com/v1/chat/completions> \\
      -H "Content-Type: application/json" \\
      -H "Authorization: Bearer $OPENAI_API_KEY" \\
      -d '{
         "model": "gpt-4o-mini",
         "messages": [{"role": "user", "content": "Say this is a test!"}],
         "temperature": 0.7
       }'
    

    发现代理没有生效

  2. 尝试:先直接添加环境变量:

    export http_proxy="<http://127.0.0.1:7890/>"
    export https_proxy="<https://127.0.0.1:7890/>"
    # 或者直接设置
    export ALL_PROXY="socks5://127.0.0.1:7890"
    

    发现报错:curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to 127.0.0.1:7890(443 error:HTTPS连接中的TLS/SSL握手失败)

  3. 测试:本来直接curl <https://ipinfo.io>(查看自己的IP地址数据)可以成功,结果export了代理反而SSL错误了

  4. 再尝试:发现macos系统自带curl命令,可能openssl库比较老,于是使用brew安装curl-openssl,并更新curlopenssl库,which curl查看是否使用了brew管理的curl 但是仍然报错:

    curl: (35) TLS connect error: error:00000000:lib(0)::reason(0)
    
  5. 最终解决:在curl命令时,使用-x参数手动指定代理(curl -x socks5://127.0.0.1:7890 <https://api.openai.com/v1/chat/completions)>

学习

  1. 终端不走系统网络代理,需要手动配置
  2. ping使用的是ICMP协议,无法用来测试代理是否正常,需要使用curl
  3. SOCKS5 代理不解析传输的数据,它将数据直接传输到目标服务器(http代理会解析),而且SOCKS5 代理支持所有协议(不仅限于http和https),在传输层工作(http在应用层工作)