"""Small client example to call POST /generate.""" from __future__ import annotations import json import os import requests from dotenv import load_dotenv load_dotenv() BASE_URL = os.getenv("CODING_LLM_URL", "http://127.0.0.1:8000") API_KEY = os.getenv("API_KEY", "") payload = { "instruction": "Fix this function and explain", "input": "def add(a,b) return a+b", } headers = {"Content-Type": "application/json"} if API_KEY: headers["x-api-key"] = API_KEY resp = requests.post(f"{BASE_URL}/generate", headers=headers, json=payload, timeout=60) if resp.status_code == 401: raise PermissionError("Unauthorized (401). Ensure API_KEY matches server configuration.") resp.raise_for_status() print(json.dumps(resp.json(), indent=2))