Your first API call,
step by step.
Connect your application to Aiman using the OpenAI Chat Completions format. Base URL: https://api.aiman.men/v1.
- Create an account and verify your email.
- Open Billing & credits and add prepaid credit. The wallet must cover the maximum request reservation before a call can run.
- Open API keys, create a key and copy it immediately. It is only shown once.
- Choose a published model from Models & pricing, then run an example below from your server or terminal.
Set your API key
Use your Aiman key, starting with sk-gw-, rather than a provider key. Send Authorization: Bearer YOUR_KEY on every API request. Keep the key in a server environment variable; never commit it or include it in browser code.
export AIMAN_API_KEY="YOUR_AIMAN_API_KEY" python -m pip install openai
$env:AIMAN_API_KEY="YOUR_AIMAN_API_KEY" python -m pip install openai
For Python, save the example as aiman_example.py, then run python aiman_example.py. cURL snippets below use Bash line continuations; use Bash or WSL for those snippets.
Choose a model
curl https://api.aiman.men/v1/models \ -H "Authorization: Bearer $AIMAN_API_KEY"
The response contains a data array; use a model's exact id such as openai/gpt-4.1-mini. Disabled models are unavailable. Your key's model restrictions also apply. Alternatively choose auto, auto/cheap, auto/balanced or auto/premium for routing. A tier must have an eligible published model.
Make your first request
POST https://api.aiman.men/v1/chat/completions accepts model, a nonempty messages array with roles and content, and an output cap such as max_tokens. The examples cap output at 128 tokens.
import os
import uuid
from openai import OpenAI
client = OpenAI(
base_url="https://api.aiman.men/v1",
api_key=os.environ["AIMAN_API_KEY"],
max_retries=0, # Check history before retrying an uncertain request.
timeout=120.0,
)
raw = client.chat.completions.with_raw_response.create(
model="openai/gpt-4.1-mini", # Use an ID from GET /v1/models.
messages=[{"role": "user", "content": "Say hello in one sentence."}],
max_tokens=128,
extra_headers={"Idempotency-Key": str(uuid.uuid4())},
)
response = raw.parse()
print(response.choices[0].message.content)
print("Request ID:", raw.headers.get("x-request-id"))
print("Actual model:", response.model)
print("Usage:", response.usage)A successful call returns HTTP 200. Read the answer from choices[0].message.content. The model field and X-Routed-Model header identify the model used; save X-Request-ID to look up this request later.
{
"id": "chatcmpl-example",
"object": "chat.completion",
"model": "openai/gpt-4.1-mini",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 18,
"completion_tokens": 10,
"total_tokens": 28
}
}Send earlier messages in the messages array when continuing a conversation. Each completion uses the context you submit; Aiman does not automatically append history to API calls. Exact models only fall back when fallback: true is supplied (Python: extra_body={"fallback": True}).
Stream a reply
Set stream=True. Read each chunk's choices[0].delta.content; usage-only chunks may have an empty choices array. The wire format is server-sent events ending with data: [DONE]. Aiman does not switch providers once output starts.
# Use the same client as the Python example above.
stream = client.chat.completions.create(
model="openai/gpt-4.1-mini",
messages=[{"role": "user", "content": "Explain APIs in two sentences."}],
max_tokens=128,
stream=True,
stream_options={"include_usage": True},
extra_headers={"Idempotency-Key": str(uuid.uuid4())},
)
for chunk in stream:
if chunk.choices:
print(chunk.choices[0].delta.content or "", end="", flush=True)
if chunk.usage:
print("\nUsage:", chunk.usage)
print()Vision requires a model with the vision capability and inline PNG, JPEG or WebP data. Remote image URLs are disabled. Cache-write presets currently accept bounded text input only. Tool calling and extra parameters must be supported by the selected model; provider-hosted tools are disabled.
Read saved conversations
Accepted requests, replies and streaming chunks are saved. View them in Conversation history, or use the same API key that created the request. A different key cannot read that request, even within the same workspace.
# Read history with the SAME API key that created the request. curl 'https://api.aiman.men/v1/history?limit=25&offset=0' \ -H "Authorization: Bearer $AIMAN_API_KEY" # Replace REQUEST_ID with X-Request-ID from the completion response. curl https://api.aiman.men/v1/history/REQUEST_ID \ -H "Authorization: Bearer $AIMAN_API_KEY"
The list returns items and next_offset. Continue with that offset until it is null. A detail response includes request, effective_request, response, chunks, response status and billing status.
DELETE /v1/history/REQUEST_ID removes the record from your pages and API results. Removed content is retained in a private database archive accessible through the application only to the platform owner. This is not permanent erasure. Billing records remain. Playground conversation removal is separate from request-history removal.
Handle errors and retries
Errors use {"error":{"message":"…","code":"…"}}. Record the HTTP status and X-Request-ID when requesting support.
| Status | What to do |
|---|---|
| 400 / 413 | Check fields, supported parameters and request size. |
| 401 | Check the Bearer key and whether it was revoked. |
| 402 | Add credit or reduce the requested output cap; the maximum budget must be reservable. |
| 403 / 404 | Check model permissions, published availability or record ownership. |
| 409 | This idempotency key was already accepted, or the record is still processing. Read history before retrying. |
| 429 | Wait, then reduce request rate, token rate or concurrency. |
| 502 / 503 / timeout | Check saved history and usage first; a provider may already have executed the request. |
Generate one unique Idempotency-Key per intended request. If an accepted request is repeated with that key, Aiman returns 409 and does not execute it again; it does not replay the old answer. Reuse the key when checking an uncertain attempt. A new key represents a new potentially billable call. The Python example disables automatic SDK retries.
Understand billing and limits
Credits are prepaid USD. The gateway reserves a conservative maximum input-and-output budget before dispatch, then settles using the frozen model price and confirmed usage. Unused reservation is released. Uncertain accounting retains a hold for review. Ordinary input, cached reads, cache writes and output have separate rates; cache-write input is not charged twice.
The service accepts at most 1 MiB per request and 256 messages. Output caps and model context limits apply, along with the limits on your API key. See current model prices and API schemas. This gateway implements Chat Completions and model/history endpoints; Responses, images, audio and embeddings endpoints are not available.