0

When setting up the API call for Jurassic (requested from https://studio.ai21.com/docs/api/), I always get the 400 error response.

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
    }
)

Output: <Response [400]>

Could anyone give me some advice please? Thank you in advance.

marius89
  • 3
  • 1
  • 1
    Does this answer your question? [400 BAD request HTTP error code meaning?](https://stackoverflow.com/questions/19671317/400-bad-request-http-error-code-meaning) – Ulrich Eckhardt Jan 11 '22 at 07:51

1 Answers1

0

Your headers are wrong, as the documentation indicates that the API key should be preceded by Bearer . Try this:

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
    }
)
RJ Adriaansen
  • 9,131
  • 2
  • 12
  • 26