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.
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 = [m for m in client.models.list().data if getattr(m, "category", "chat") == "chat"]
if not models:
raise RuntimeError("No models available")
answer = client.chat.completions.create(
model=models[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":"or-aion-labsaion-35-f8982c4efe","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].
Embeddings and reranking
Enable ai:embedding or ai:rerank on your key. Plain text and batches of up to 128 texts are supported. Only input tokens are billed.
# Choose a model with category="embedding" from /v1/models vector = client.embeddings.create(model="EMBEDDING_MODEL_ID", input=["Hello", "World"], encoding_format="float") print(vector.usage.prompt_tokens)
curl https://servernet.cloud/v1/rerank \
-H "Authorization: Bearer $SERVERNET_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: rerank-001" \
-d '{"model":"RERANK_MODEL_ID","queries":["capital?"],"documents":["Tehran"]}'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.
Generate images, speech and video
Choose a ready media model from the model list and enable ai:native on your key. Each model page describes its inputs. Use Data URLs for input files: total requests are limited to 8 MB, PCM WAV audio to 60 seconds, and H.264 MP4 video to 6 MB, 10 seconds and 1080p. Video is fully decoded before admission. Individual models may impose lower limits.
curl https://servernet.cloud/v1/inference \
-H "Authorization: Bearer $SERVERNET_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: media-001" \
-d '{"model":"NATIVE_MODEL_ID","prompt":"A blue cube in a sunny garden"}'
Video and music initially return HTTP 202 with id and result_url. Read that URL with the same key every five seconds until the result is ready. Reusing the same Idempotency-Key and body does not purchase another execution. The final charge is recorded in X-ServerNet-Charge-Irt and your usage history.
curl https://servernet.cloud/v1/inference/REQUEST_ID \ -H "Authorization: Bearer $SERVERNET_API_KEY"