Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.zerogpu.ai/llms.txt

Use this file to discover all available pages before exploring further.

Install the published client from PyPI:
pip install zerogpu-api
import os
from zerogpu import ZerogpuApi

client = ZerogpuApi(
    api_key=os.environ["ZEROGPU_API_KEY"],
    project_id=os.environ["ZEROGPU_PROJECT_ID"],
)

# Many models accept plain string `input`; others accept a message list — see API reference.
response = client.responses.create_response(
    model=os.environ.get("ZEROGPU_MODEL", "YOUR_MODEL"),
    input="Your input text here...",
    text={"format": {"type": "text"}},
)
print(response)
Source and regeneration workflow: zerogpu/SDK on GitHub.

Chat completions (/v1/chat/completions)

For models that use the chat route:
from zerogpu import ChatMessage

client.chat.create_chat_completion(
    model="YOUR_MODEL",
    messages=[ChatMessage(role="user", content="Hello")],
)
See Chat completions.

Responses with metadata

Pass metadata={...} into create_response when the model supports it. See Responses.

Raw HTTP (requests)

If you prefer not to use the SDK, call the endpoint directly.
import requests

url = "https://api.zerogpu.ai/v1/responses"
headers = {
    "content-type": "application/json",
    "x-api-key": "YOUR_API_KEY",
    "x-project-id": "YOUR_PROJECT_ID",
}
payload = {
    "model": "YOUR_MODEL",
    "input": [
        {
            "role": "user",
            "content": "Your input text here...",
        }
    ],
    "text": {
        "format": {
            "type": "text"
        }
    },
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())

Using environment variables

import os
import requests

url = "https://api.zerogpu.ai/v1/responses"
headers = {
    "content-type": "application/json",
    "x-api-key": os.environ["ZEROGPU_API_KEY"],
    "x-project-id": os.environ["ZEROGPU_PROJECT_ID"],
}
payload = {
    "model": "YOUR_MODEL",
    "input": [
        {
            "role": "user",
            "content": "Your input text here...",
        }
    ],
    "text": {
        "format": {
            "type": "text"
        }
    },
}

response = requests.post(url, headers=headers, json=payload)
result = response.json()

print(result["output"][0]["content"][0]["text"])

Error handling

import requests

try:
    response = requests.post(url, headers=headers, json=payload)
    response.raise_for_status()
    result = response.json()
    print(result["output"][0]["content"][0]["text"])
except requests.exceptions.HTTPError as e:
    if e.response.status_code == 401:
        print("Invalid API key")
    else:
        print(f"Error: {e.response.status_code}")
except requests.exceptions.RequestException as e:
    print(f"Request failed: {e}")

Install dependencies

pip install requests