0
0
Prompt Engineering / GenAIml~20 mins

API key management in Prompt Engineering / GenAI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
API Key Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why is it important to rotate API keys regularly?

Imagine you have an API key that allows access to a machine learning service. Why should you change (rotate) this key regularly?

ATo increase the speed of API responses.
BTo prevent unauthorized access if the key is leaked or stolen.
CTo reduce the cost of using the API service.
DTo make the API key longer and more complex.
Attempts:
2 left
💡 Hint

Think about what happens if someone else gets your key.

Predict Output
intermediate
2:00remaining
What is the output of this API key validation code?

Consider this Python code that checks if an API key is valid by length and prefix:

def is_valid_key(key):
    return key.startswith('sk-') and len(key) == 32

print(is_valid_key('sk-12345678901234567890123456789'))
print(is_valid_key('pk-12345678901234567890123456789'))
print(is_valid_key('sk-12345'))

What will be printed?

A
True
False
False
B
False
False
False
C
True
True
False
D
True
False
True
Attempts:
2 left
💡 Hint

Check the prefix and length conditions carefully.

Model Choice
advanced
2:00remaining
Which API key storage method is safest for a deployed ML model?

You deployed a machine learning model that calls an external API. Which method is safest to store the API key?

AHardcoding the API key directly in the model's source code.
BEmbedding the API key in client-side JavaScript code.
CStoring the API key in environment variables on the server.
DSaving the API key in a public GitHub repository.
Attempts:
2 left
💡 Hint

Think about who can access the stored key in each method.

Hyperparameter
advanced
1:30remaining
What is the effect of setting a very short API key expiration time?

Some API keys can be set to expire quickly (e.g., every 5 minutes). What is a likely effect of this setting?

AHas no effect on security or service availability.
BReduces security because keys are reused more often.
CIncreases API call speed by caching keys longer.
DImproves security by limiting key lifetime but may cause frequent service interruptions.
Attempts:
2 left
💡 Hint

Think about trade-offs between security and usability.

🔧 Debug
expert
2:30remaining
Why does this API key check always fail?

Look at this Python code snippet that should check if an API key is valid:

def check_key(key):
    if key == 'sk-1234567890abcdef1234567890abcdef':
        return True
    else:
        return False

print(check_key('sk-1234567890abcdef1234567890abcdef '))

Why does the function return False even though the printed key looks the same?

AThe input key has a trailing space, so it does not exactly match the stored key.
BThe function uses '==' which cannot compare strings correctly.
CThe print statement modifies the key before checking.
DThe stored key is missing a character at the end.
Attempts:
2 left
💡 Hint

Check for invisible characters like spaces.