Skip to content

Your first request

Create a key, add credits and make a Python or HTTP request.

SingleAPI accepts a subset of OpenAI Chat Completions, so you can use the official OpenAI Python SDK with your SingleAPI key and SingleAPI /v1 URL. The model provider is selected by the model ID, not by the SDK you use.

1. Get a key and choose a model

Sign in to the SingleAPI dashboard. Open Models to see enabled models and prices. Open API Keys, create a key with access to your chosen model, and copy its secret when shown; you cannot retrieve the full secret later. For a managed request, use Add credits on Overview first. A restricted key with no selected models cannot call any model.

Use the API URL for your SingleAPI deployment. The setup below shows this deployment's API URL; replace its origin if you connect to another server. Local development normally uses http://localhost:8010. The SDK base URL ends in /v1 exactly once. Keep the key in your environment or secret manager, never in source control.

sh
export SINGLEAPI_BASE_URL="https://staging.singleapi.ai/api/v1"
export SINGLEAPI_API_KEY="YOUR_SINGLEAPI_KEY"
export SINGLEAPI_MODEL_ID="openai/gpt-4o-mini" # Replace with an enabled model allowed by your key.

2. Make a chat request

Install the Python SDK (python3 -m pip install 'openai>=2,<3'), save this as first_request.py, and run python3 first_request.py:

python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["SINGLEAPI_API_KEY"],
    base_url=os.environ["SINGLEAPI_BASE_URL"],
)
model_id = os.environ["SINGLEAPI_MODEL_ID"]
available = {model.id for model in client.models.list().data}
if model_id not in available:
    raise SystemExit(f"{model_id} is not available to this key. Choose one of: {sorted(available)}")

response = client.chat.completions.create(
    model=model_id,
    messages=[{"role": "user", "content": "Say hello in one sentence."}],
    max_tokens=100,
)
print(response.choices[0].message.content)
print("Request ID:", response.id)
print("Usage:", response.usage)

The models.list() call shows only enabled models allowed by this key. The completion uses your SingleAPI key to authenticate; SingleAPI sends the request to the provider for the chosen model. Open Usage in the dashboard for totals and trends; use the usage API with the request ID for individual request detail. Provider usage can be absent; in that case response.usage is None.

HTTP alternative

The same environment variables also work with curl:

sh
curl "$SINGLEAPI_BASE_URL/models" \
  -H "Authorization: Bearer $SINGLEAPI_API_KEY"

curl "$SINGLEAPI_BASE_URL/chat/completions" \
  -H "Authorization: Bearer $SINGLEAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"model\":\"$SINGLEAPI_MODEL_ID\",\"messages\":[{\"role\":\"user\",\"content\":\"Say hello in one sentence.\"}],\"max_tokens\":100}"

Next, stream a response, bring your own provider key, or explore JSON responses, function tools, provider web search, and Anthropic web fetch. For exact request fields and errors, use the API reference.

Need a hand?

Manage your keys, credits and usage from the dashboard.

Open the dashboard