【问题标题】:Failed API Call - How to handle "Error 400" for Jurassic API?API 调用失败 - 如何处理侏罗纪 API 的“错误 400”?
【发布时间】:2022-01-11 06:51:44
【问题描述】:

在设置 Jurassic 的 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
    }
)

输出:

有人能给我一些建议吗?提前谢谢你。

【问题讨论】:

标签: python api call transformer jurassic


【解决方案1】:

您的标头错误,因为文档表明 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
    }
)

【讨论】:

    猜你喜欢
    • 2018-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-16
    • 2018-10-09
    • 1970-01-01
    • 2012-05-10
    • 2020-06-10
    相关资源
    最近更新 更多