Skip to content

Getting Started: Python

Use Python (3.9+) with requests to call the BetterPrompt API.

python
import os
import requests

API_KEY = os.getenv("BETTERPROMPT_API_KEY", "YOUR_API_KEY")
PROMPT_VERSION_ID = os.getenv("BP_PROMPT_VERSION_ID", "YOUR_PROMPT_VERSION_ID")

resp = requests.post(
    "https://api.betterprompt.me/v1/runs",
    headers={
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json",
    },
    json={
        "promptVersionId": PROMPT_VERSION_ID,
        "inputs": {"textInputs": {"yourField": "value"}},
    },
)
print(resp.json())