Skip to content
Documentation · API reference
Docs / API & features

API reference

Send model requests over HTTP or WebSocket. This reference covers authentication, request formats, response fields and session limits.

On this page

Make a request

Use https://xavainf.com/v1 as the base URL for an OpenAI SDK. For HTTP calls, use the complete endpoint from the table below and send your API key in Authorization: Bearer <key>.

Choose an exact model id from Models. Its page lists the supported inputs and price. The catalog and voice directory are public. The request examples below use an API key and your account balance.

terminal · replace the placeholder
export XINF_API_KEY="xk_live_REPLACE_WITH_YOUR_KEY"
TaskEndpointExample model / result
CatalogGET /v1/modelsModel ids, capabilities and prices
textPOST /v1/chat/completionsaisingapore/gemma-sea-lion-v4-27b-it
imagePOST /v1/images/generationsalibaba/qwen-image-3.0-pro
videoPOST /v1/media/generationsalibaba/hh1-t2v
audioPOST /v1/media/generationsdeepgram/aura-1
embeddingsPOST /v1/embeddingsbaai/bge-base-en-v1.5
Realtime voiceGET /v1/realtime · WebSocketxai/grok-voice, elevenlabs/voice-agent
Voice directoryGET /v1/voicesVoice ids, compatible models and samples

Chat completions

Send model and a messages array to POST /v1/chat/completions. Each message has a role and content. Tool calls, image inputs and structured output depend on the selected model.

The response follows the OpenAI Chat Completions format: read the reply from choices[0].message.content and token counts from usage. These examples read the key exported above.

Python · pip install openai
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://xavainf.com/v1",
    api_key=os.environ["XINF_API_KEY"],
)

r = client.chat.completions.create(
    model="openai/gpt-5.4",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(r.choices[0].message.content)
curl
curl https://xavainf.com/v1/chat/completions \
  -H "Authorization: Bearer $XINF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"openai/gpt-5.4","messages":[{"role":"user","content":"Hello!"}]}'

Stream a reply

Set stream: true to receive server-sent events. Read text from each chunk's choices[0].delta.content; a final usage chunk reports token counts before the stream ends. For curl, use -N to disable output buffering.

Models whose catalog endpoint is /v1/responses use the Responses API instead. Its request fields and stream events differ from Chat Completions. For failures or interrupted streams, follow errors and retries.

Generate images

Send a model and prompt to POST /v1/images/generations. Image size, count and editing inputs vary by model, so check its parameter reference before adding optional fields.

curl · image generation
curl https://xavainf.com/v1/images/generations \
  -H "Authorization: Bearer $XINF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"alibaba/qwen-image-3.0-pro","prompt":"a pixel-art rocket","size":"1024x1024"}'

Read generated image links from data[].url. Each entry includes expires_at in Unix seconds. Request response_format: "b64_json" to also receive image bytes in data[].b64_json. Download files before their links expire.

Generate video

Video uses POST /v1/media/generations with a model and an input object. A text-to-video model accepts a prompt; image-to-video and editing models also need the reference fields shown on their model pages.

The example requests four seconds of video. Supported durations and resolutions are model-specific. A generation can take a minute or more; the HTTP request waits for the result.

curl · video generation
curl https://xavainf.com/v1/media/generations \
  -H "Authorization: Bearer $XINF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"alibaba/hh1-t2v","input":{"prompt":"a pixel-art rocket lifting off","duration":4}}'

Read a media response

Video and audio requests return the same response envelope. Use output for the model's result and files for downloadable media. For transcription and other text-output tasks, the result may have no files.

FieldMeaning
id / modelThe request id and resolved model id.
outputThe model's result; its structure depends on the task.
files[].urlA download link on this site.
files[].content_type / bytesThe file's MIME type and size.
files[].expires_atThe file's expiry time in Unix seconds.

Generate or transcribe audio

Audio also uses POST /v1/media/generations. A speech model takes text; transcription models take an audio reference; music and sound models accept their own inputs. Use the selected model's parameter names inside input.

curl · text to speech
curl https://xavainf.com/v1/media/generations \
  -H "Authorization: Bearer $XINF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"deepgram/aura-1","input":{"text":"Hello from one key."}}'

For speech generation, select a compatible voice from the voice directory. For transcription, supply a public HTTPS URL or a temporary reference upload. Results use the media response fields above.

Create embeddings

Send an embeddings model and input to POST /v1/embeddings. Input can be one string or an array of up to 256 strings. The response contains one vector per input, in the same order.

curl · embeddings
curl https://xavainf.com/v1/embeddings \
  -H "Authorization: Bearer $XINF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"baai/bge-base-en-v1.5","input":"The quick brown fox"}'

Read vectors from data[].embedding and match them with data[].index. Vectors are arrays of floats by default; set encoding_format: "base64" for base64 output. Token usage is reported in usage.

Realtime voice

Connect to /v1/realtime?model=<id> over WebSocket with the bearer header and the realtime subprotocol. Eligible models have "realtime": true in the catalog. Audio and transcripts pass through without being stored.

The connection uses OpenAI Realtime events. The default audio format is PCM16 at 24 kHz, mono; PCM at 8–48 kHz and G.711 are also accepted. Configure the session before sending audio.

EventWhat it does
session.updateSet the voice, instructions, turn detection and audio formats.
input_audio_buffer.appendSend a base64-encoded audio chunk.
input_audio_buffer.commit + response.createFinish a manual turn and request a reply, or use server voice activity detection.
response.output_audio.deltaReceive generated audio. Transcript events accompany the conversation.
response.doneThe current reply has finished.
Node.js · npm install ws
import WebSocket from "ws";

const ws = new WebSocket("wss://xavainf.com/v1/realtime?model=xai/grok-voice", "realtime", {
  headers: { Authorization: `Bearer ${process.env.XINF_API_KEY}` },
});
ws.on("open", () => {
  ws.send(JSON.stringify({ type: "session.update", session: {
    voice: "ara", instructions: "Be brief.",
    turn_detection: { type: "server_vad" },
    audio: { input: { format: { type: "audio/pcm", rate: 24000 } }, output: { format: { type: "audio/pcm", rate: 24000 } } },
  } }));
  // stream microphone audio: base64 PCM16, 24 kHz mono
  // ws.send(JSON.stringify({ type: "input_audio_buffer.append", audio: chunk.toString("base64") }));
});
ws.on("message", (raw) => {
  const e = JSON.parse(raw.toString());
  if (e.type === "response.output_audio.delta") play(Buffer.from(e.delta, "base64"));
  if (e.type === "response.output_audio_transcript.delta") process.stdout.write(e.delta);
  if (e.type === "billing.updated") console.log("\nsession cost $" + e.session.cost_usd);
});

This example shows connection setup and event handling. Connect your microphone chunks to input_audio_buffer.append and implement play(pcm) for your audio output.

Session billing and limits

Usage settles after each response and at least once a minute while audio is active. The server sends billing.updated with that segment's cost and the session total. The balance must cover about two minutes of audio before connecting and before each new segment.

Function tools are supported. Provider-hosted web search, remote MCP tools and unknown client events return an error event. The default session limits are:

LimitConnection behavior
15 minutes per sessionCloses with code 4001.
3 minutes idleCloses with code 4003.
Insufficient balanceSends insufficient_balance, then closes with 4002.
Concurrent sessionsUp to two per account.

ElevenLabs voice sessions

elevenlabs/voice-agent uses the same connection with PCM16 at 16 kHz in both directions. Set voice, instructions, language and first_message through session.update before or as the session starts; they stay fixed afterward.

The agent handles turn-taking and interruptions. Use input_audio_buffer.commit to end a push-to-talk turn; response.create is unnecessary. Billing covers connected time, including silence. Sessions are limited to a few minutes while capacity is constrained. Capacity failures return voice_unavailable and close code 4503, without charging the unsettled segment.

Find a voice

GET /v1/voices is a public directory of voices and the models that accept them. Filter by model, maker, gender or language; use q for text search.

A voice record's voice value goes in the field named by param, such as voice_id, voice or speaker. Records also include descriptive metadata and a preview_url when a sample is available.

curl · look up a compatible voice
curl "https://xavainf.com/v1/voices?model=elevenlabs/eleven-v3"

# Put the chosen voice value in the field named by param.
curl "https://xavainf.com/v1/media/generations" \
  -H "Authorization: Bearer $XINF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"elevenlabs/eleven-v3","input":{"text":"Hello!","voice_id":"JBFqnCBsd6RMkjVDRZzb"}}'

Use GET /v1/voices/{id} to read one record and GET /v1/voices/{id}/preview to play its MP3 sample. For an ElevenLabs realtime session, filter the directory with model=elevenlabs/voice-agent.

Provider-compatible APIs

Use these routes when your SDK or coding agent expects a provider's native request format. They use the same account key and balance. Each format keeps its own request fields, streaming events and error shape.

FormatEndpointsModels and authentication
Anthropic MessagesPOST /v1/messages
POST /v1/messages/count_tokens
Anthropic models; native ids map to catalog ids. Use x-api-key or a bearer header.
OpenAI ResponsesPOST /v1/responsesOpenAI models; bare ids such as gpt-5.4-mini also work. Use a bearer header.
GeminiPOST /v1beta/models/{model}:generateContent
:streamGenerateContent?alt=sse
:countTokens
Gemini ids or a full chat-model id. Use x-goog-api-key.

For Anthropic-style model discovery, send anthropic-version to GET /v1/models. Gemini clients use GET /v1beta/models. Token-count endpoints return free estimates.

See Codex & Claude Code for complete base URL, key and model settings, plus small authenticated requests to verify the connection.

Download and retain generated files

Generated files are deleted after 24 hours. Every media link includes expires_at, expressed in Unix seconds. Copy the file to your own storage before that time; an expired link returns 410 Gone.

Media endpoints are in preview. Check the model's inputs and billing unit before integrating: a unit may be an image, a second of video, a character or a minute of audio. For request failures, retain x-request-id and use the error reference.