0

在为侏罗纪设置 API 调用(从https://studio.ai21.com/docs/api/请求)时,我总是收到 400 错误响应。

import json
import requests

   requests.post(
    "https://api.ai21.com/studio/v1/j1-large/complete",
    headers={"Authorization": "PERSONAL API KEY"}, 
    json={
        "prompt": "Life is like", 
        "numResults": 1, 
        "maxTokens": 8, 
        "stopSequences": ["."],
        "topKReturn": 0,
        "temperature": 0.0
    }
)

输出:<响应 [400]>

有人可以给我一些建议吗?先感谢您。

4

1 回答 1

0

您的标头是错误的,因为文档表明 API 密钥应该以Bearer . 尝试这个:

import json
import requests

YOUR_API_KEY = 12345678 #define API key here

requests.post(
    "https://api.ai21.com/studio/v1/j1-large/complete",
    headers={"Authorization": f"Bearer {YOUR_API_KEY}"},
    json={
        "prompt": "Life is like", 
        "numResults": 1, 
        "maxTokens": 8, 
        "stopSequences": ["."],
        "topKReturn": 0,
        "temperature": 0.0
    }
)
于 2022-01-11T07:49:11.937 回答