api4students API Documentation
A drop-in OpenAI & Anthropic compatible AI API with chat, image generation, text-to-speech, and speech-to-text. Use any OpenAI or Anthropic SDK — just change the base URL and API key.
Quick start
Authentication
All API requests require a Bearer token in the Authorization header. Create one in the dashboard.
Authorization: Bearer a4s-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxChat Completions (OpenAI-compatible)
Drop-in replacement for POST /v1/chat/completions. Supports streaming, tools, JSON mode, vision — depending on the model. If the site admin has set a default system prompt (global or per-model), it is prepended as the first system message; your own system message (if any) is kept after it.
curl https://api.namansoni.in/v1/chat/completions \
-H "Authorization: Bearer a4s-xxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "llama-3.1-8b-instant",
"messages": [{"role":"user","content":"Hello!"}],
"stream": false
}'Streaming
Set "stream": true for Server-Sent Events (SSE) — OpenAI-compatible.
from openai import OpenAI
client = OpenAI(api_key="a4s-xxxx", base_url="https://api.namansoni.in/v1")
stream = client.chat.completions.create(
model="llama-3.1-8b-instant",
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")Tool calling
Pass tools array — OpenAI-compatible format. Only models with the tools capability accept this.
curl https://api.namansoni.in/v1/chat/completions \
-H "Authorization: Bearer a4s-xxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "<tool-capable-model>",
"messages": [{"role":"user","content":"What is the weather in Paris?"}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type":"string"}},
"required": ["city"]
}
}
}]
}'JSON mode
Force JSON-formatted output with response_format. Only models with the json_mode capability accept this.
curl https://api.namansoni.in/v1/chat/completions \
-H "Authorization: Bearer a4s-xxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "<json-capable-model>",
"messages": [{"role":"user","content":"List 3 fruits with colors."}],
"response_format": {"type": "json_object"}
}'Anthropic-compatible (/v1/messages)
Use the official Anthropic SDK with our base URL. We translate Anthropic ↔ OpenAI internally.
import anthropic
client = anthropic.Anthropic(
api_key="a4s-xxxx",
base_url="https://api.namansoni.in",
)
response = client.messages.create(
model="llama-3.1-8b-instant",
max_tokens=256,
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.content[0].text)List models
curl https://api.namansoni.in/v1/modelsNo auth required. Returns model IDs, types (chat/image/tts/stt), capabilities, pricing, and context windows.
Image Generation (OpenAI-compatible)
POST /v1/images/generations — same request shape as OpenAI's images API. Use any image model from /models (type: image). Billing is flat per request (× n images). Works with OpenAI-compatible upstreams and Pollinations-style image services.
curl https://api.namansoni.in/v1/images/generations \
-H "Authorization: Bearer a4s-xxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "flux",
"prompt": "a cute robot studying with books, digital art",
"n": 1,
"size": "1024x1024",
"response_format": "b64_json"
}'Response follows the OpenAI images schema: { "created": …, "data": [{ "url" | "b64_json" }] }.
Text-to-Speech (OpenAI-compatible)
POST /v1/audio/speech — same request shape as OpenAI's TTS API. Returns binary audio (mp3/wav per the upstream provider). Billed flat per request, or per 1M input characters when the admin sets a per-char price.
curl https://api.namansoni.in/v1/audio/speech \
-H "Authorization: Bearer a4s-xxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "whisper-large-v3-tts",
"input": "api4students makes AI APIs free for students.",
"voice": "alloy",
"response_format": "mp3"
}' \
--output speech.mp3Speech-to-Text (OpenAI-compatible)
POST /v1/audio/transcriptions — multipart/form-data, same as OpenAI's Whisper API. Upload an audio file and get the transcription back as JSON.
curl https://api.namansoni.in/v1/audio/transcriptions \
-H "Authorization: Bearer a4s-xxxx" \
-F "file=@lecture.mp3" \
-F "model=whisper-large-v3"Response: { "text": "…" } (plus provider extras like duration).
Default system prompt
The site admin can set a global default system prompt (admin panel → Settings) and a per-model one (e.g. a model that always introduces itself as Kimi). The resolved prompt is prepended as the first system message on every chat request — on both /v1/chat/completions and /v1/messages. If your request carries its own system message, it is kept after the default, so both apply. Models that don't support system messages never receive one.
Model names, fallbacks & per-model config
Every model on this platform has a public name (what you put in the model field) and a hidden upstream id (what the provider actually calls it). They can be completely different — e.g. you request gpt-image and the gateway transparently asks the upstream for its imagine model. Both names are listed in GET /v1/models (the id and the aliases field).
Models can also have fallback models: if the first upstream is rate-limited or down, the gateway automatically retries with the fallback (up to 3) before giving up — on every endpoint, including images, TTS and STT. You are billed as the model that actually served your request.
Admins can attach a per-model request config (defaults, whitelists, forced values) for full control — e.g. force a default image size, restrict allowed voices, or lock a response format. If your request uses a value outside the whitelist you'll get an HTTP 400 with the allowed values.
Want to try all of this in your browser? The playground has four tabs — chat, image generation, text-to-speech and transcription — all running against the real API with your key.
Available models
No models listed yet. Check back soon.