You are given documentation for a sandbox credit-management API. The documentation describes API operations for creating an account, adding credits, checking the account balance, and spending credits. AI-assisted coding tools are allowed during the exercise.
Build a small script or command-line program that performs the full workflow below:
-
Discover or configure the API base URL and authentication key. If the documentation page only shows runnable examples, use the browser developer tools or network inspector to identify the actual request URL, headers, and payload format.
-
Create a new account.
-
Add a fixed amount of credits to that account, for example
100
credits.
-
Retrieve and print the current balance.
-
Spend a fixed amount of credits, for example
30
credits.
-
Retrieve and print the final balance.
-
Validate that the final balance is correct based on the initial top-up and spend amount.
Your implementation should be easy to run, should avoid hardcoding secrets, should handle non-successful HTTP responses clearly, and should keep the API calls organized into reusable functions.