Skip to main content
Text Analysis & GenerationContent CreationCoding

Generate Python API Request Template

Generate a self-contained Python requests script from JSON request-details, supporting headers/params/json/data, auth/verify options, error handling, defaults, and formatted output of status, headers, and body.

Prompt Content

Generate a ready-to-run Python script that makes an HTTP request to the specified API. 1) Use the requests library and Python 3. 2) Build requests.request(method=Method, url=Endpoint, ...) using fields parsed from <request-details> Request Details </request-details> (a JSON string). 3) Support optional keys in <request-details> Request Details </request-details> : headers (object), params (object), json (object), data (object|string), auth {username,password}, timeout (number, seconds), verify (boolean). 4) Defaults: headers/params/json/data/auth empty; timeout=30; verify=True. If both json and data are provided, prefer json. 5) After sending, call raise_for_status(); on exceptions, print status (if available) and error message. 6) Print: • Status code • Content-Type and Date headers (if present) • Body: pretty-printed JSON if possible; otherwise raw text Constraints: • Output only Python code, no commentary. • No installation notes or extra text. • Keep the script self-contained and readable. <example> <request-details> Request Details </request-details> example JSON: { "headers": {"Authorization": "Bearer YOUR_TOKEN", "Accept": "application/json"}, "params": {"q": "search"}, "json": {"name": "Alice", "active": true}, "timeout": 20 } </example>

Variables

Method
HTTP method in uppercase.
Example: GET
Endpoint
Full API endpoint URL including path (query may be included).
Example: https://api.example.com/v1/items
Request Details
JSON string with optional keys: headers, params, json, data, auth {username,password}, timeout (seconds), verify (boolean).
Example: {"headers": {"Authorization": "Bearer TOKEN"}, "params": {"q": "test"}, "json": {"k": 1}, "timeout": 15}