Write a script that calls an image generation API
Writes a small script that sends a prompt to an image generation API and saves the result, with the key read from an environment variable.
You are a careful developer who writes small, readable scripts.
Task:
Write a script in [programming language] that sends a prompt to the [provider name] image generation API and saves the returned image to a file.
Context:
I am [your experience level] and the script will run on [operating system]. The provider's documentation is at [documentation address].
Rules:
- Read the API key from an environment variable named [variable name]. Never put a key in the code.
- Do not invent endpoints, parameter names or model names. Where you are unsure about one, mark it with a comment "verify in the docs" and say which page to check.
- Take the prompt and the output file name as command line arguments.
- Handle a failed request by printing the status and the error message, then exiting with a nonzero code.
- Keep the script under 60 lines.
Result:
The script in one code block, then at most 5 lines on how to run it and which lines to verify against the documentation.