API Integration
The API matches the OpenAI chat completions protocol. Request bodies are forwarded upstream verbatim; no fields are stripped.
-
Base URL:
https://aiapigpt.com/v1 - Authentication: API key (starts with sk-)
- Protocol: OpenAI chat completions (/v1/chat/completions)
Replace sk-your-sub2api-key with your own key. Keep it safe and never commit it to a repository.
1. Base URL and headers
Send Authorization: Bearer <your API key> with every request. An invalid key and a disabled key return different status codes (401 / 403), and neither reveals whether the key exists.
Base URL
Authorization: Bearer sk-your-sub2api-key Content-Type: application/json
2. Endpoints
| Endpoints | Notes |
|---|---|
| POST /v1/chat/completions | Chat completion. With stream: true the response is streamed as SSE chunks. |
| GET /v1/models | List the models you can call right now (authentication required). Only models that are priced, backed by a usable upstream account, and within your key's allowlist are returned — so nothing in the list is un-callable. |
| GET /healthz | Health check. No authentication required. |
| Any other path | Always 404. No other OpenAI endpoints are implemented (images, audio, embeddings, etc.). |
3. Example request
3. 1 curl
curl https://aiapigpt.com/v1/chat/completions \
-H "Authorization: Bearer sk-your-sub2api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Hello"}]
}'
3. 2 Python SDK (openai)
from openai import OpenAI
client = OpenAI(
base_url="https://aiapigpt.com/v1",
api_key="sk-your-sub2api-key",
)
resp = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)
4. Useful response headers
- X-Request-Id
- The request ID. You may also send your own X-Request-Id header to line up with your own logs.
- X-Sub2Api-Charge
- ok = charged; pending = charging failed and was queued for replay, which retries automatically.