0
0
Prompt Engineering / GenAIml~10 mins

API-based deployment in Prompt Engineering / GenAI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to send a POST request to the API endpoint.

Prompt Engineering / GenAI
response = requests.[1]('https://api.example.com/predict', json=data)
Drag options to blanks, or click blank then click option'
Apost
Bget
Cput
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST causes the server to not receive data.
Using PUT or DELETE when only POST is accepted.
2fill in blank
medium

Complete the code to extract the JSON response from the API call.

Prompt Engineering / GenAI
result = response.[1]()
Drag options to blanks, or click blank then click option'
Ajson
Bcontent
Ctext
Dstatus_code
Attempts:
3 left
💡 Hint
Common Mistakes
Using response.text returns raw string, not parsed JSON.
Using response.status_code returns the HTTP status, not data.
3fill in blank
hard

Fix the error in the code to handle API errors properly.

Prompt Engineering / GenAI
if response.status_code != [1]:
    print('Error:', response.status_code)
Drag options to blanks, or click blank then click option'
A201
B404
C500
D200
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 404 or 500 instead of 200 causes false error detection.
Using 201 which means resource created, not general success.
4fill in blank
hard

Fill both blanks to prepare headers and send the API request with authentication.

Prompt Engineering / GenAI
headers = {'Authorization': 'Bearer [1]'}
response = requests.post(url, json=data, headers=[2])
Drag options to blanks, or click blank then click option'
Aapi_key_123
Bdata
Cheaders
Dtoken_abc
Attempts:
3 left
💡 Hint
Common Mistakes
Passing data instead of headers causes authentication failure.
Using wrong token string in Authorization header.
5fill in blank
hard

Complete the code to parse the prediction from the API response dictionary.

Prompt Engineering / GenAI
prediction = result['output'[1]0]
Drag options to blanks, or click blank then click option'
A[
B][
D]
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of brackets causes errors.
Missing brackets leads to wrong data access.