Integration guide
Create projects and API keys, connect with Python or curl, use streaming, set budgets and understand ServerNet AI API errors.
- Check the model and its availability.
- Sign in, create a project and a key with ai:chat and ai:models:read.
- Fund your wallet and send a test request with a small output limit.
- Review the request usage and charge in your dashboard.
The key is shown once. Store it in a server environment variable. Keep it out of browser code, GitHub and logs.
Base URL
https://servernet.cloud/v1
Fetch available models with GET /v1/models first. Use the returned id as the model name in your requests.
curl https://servernet.cloud/v1/models \ -H "Authorization: Bearer $SERVERNET_API_KEY"
Python example
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["SERVERNET_API_KEY"],
base_url="https://servernet.cloud/v1",
max_retries=0,
)
models = client.models.list()
if not models.data:
raise RuntimeError("No models available")
answer = client.chat.completions.create(
model=models.data[0].id,
messages=[{"role": "user", "content": "Hello"}],
max_tokens=128,
extra_headers={"Idempotency-Key": "my-request-001"},
)
print(answer.choices[0].message.content)curl example
curl https://servernet.cloud/v1/chat/completions \
-H "Authorization: Bearer $SERVERNET_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: my-request-002" \
-d '{"model":"di-anthropicclaude-fable-5-86c0c8bf10","messages":[{"role":"user","content":"Hello"}],"max_tokens":128}'Set stream=true for streaming. The final usage event contains token counts and servernet_charge_irt, followed by [DONE].
Use the same Idempotency-Key when retrying an identical request. Successful responses are replayed without a second charge for 24 hours. Do not automatically retry when x-should-retry:false is present.
Errors and tracking
401 invalid key; 402 balance or budget limit; 403 key or project access; 429 rate limit; 503 model or provider unavailable. If the connection fails after sending, the hold remains while usage is reconciled. Retain X-Request-Id for support.