Skip to content

AI Runtime

Core LLM inference — chat, embeddings, vision, image generation, speech (TTS/ASR) — is OpenAI-compatible: call it with the official openai SDK pointed at the infrai base_url. The methods here are the infrai-native extensions: batch, cost/token tooling, rerank, image upscale, TTS voices and live voice sessions.

OpenAI-compatible endpoints

Core AI inference (chat, embeddings, image, TTS, ASR, moderation, models) is served on the standard OpenAI API surface — point the OpenAI SDK at infrai's base URL. Full examples → Looking for chat, embeddings, images or speech? Those are served on the OpenAI-compatible API — point the OpenAI SDK at infrai →

Endpointinfrai capabilityPurpose
POST /v1/chat/completionsai.chatChat completions — text, vision and tool calls, with streaming.
POST /v1/embeddingsai.embedText embeddings for search and RAG.
POST /v1/images/generationsai.imageImage generation from a text prompt.
POST /v1/audio/speechai.ttsText-to-speech — synthesize spoken audio.
POST /v1/audio/transcriptionsai.asrSpeech-to-text — transcribe an audio file.
POST /v1/moderationsai.moderationClassify whether content violates usage policy.
GET /v1/modelsai.models.listList every model a verified, routable vendor serves.
GET /v1/models/{model}ai.models.getRetrieve one model's details (pricing, context, availability).

1. Overview

Base path: https://api.infrai.cc/v1/ai
Auth header: Authorization: Bearer $INFRAI_API_KEY
bash
# Call any /v1/ai capability over raw HTTP — no SDK to install.
# curl:
curl https://api.infrai.cc/v1/ai/... \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json"

2. Methods (11)

2.1ai.batch.submit

POST /v1/ai/batch/submit

Submit a batch of AI requests as a single asynchronous batch processing task, and the batch mode is transparently transmitted at the original cost.

Parameters

NameTypeRequiredDescription
requestsBatchRequestItem[]
Required
An array of batch request entries, each containing capability and body.
≥ 1 item
batch_timeoutstringOptionalThe maximum completion time for batch processing (such as 24h). Entries that are not completed after the timeout are processed as failures.
default: "24h"e.g. 1h
metadataRecord<string, unknown>OptionalCustom key-value metadata attached to the batch task.
idempotency_keystringOptionalOptional dedup key; identical retries return the same result.

Returns

BatchSubmitResult { batch_id, state, total_count, estimated_eta?, estimated_cost_usd? }
NameTypeDescription
batch_idstringUnique identifier for this batch job
pattern: ^batch_[A-Za-z0-9]{20,}$
state"connecting" | "queued" | "in_progress" | "completed" | "failed" | "expired" | "cancelled"Current lifecycle state of this resource
total_countintegerTotal number of items across all pages
≥ 1
estimated_etastring | nullEstimated time remaining for batch completion
format: date-time
estimated_cost_usdnumber | nullEstimated total cost for the batch in USD
≥ 0

Example

One-time prep (each example is assumed to be complete):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/ai/batch/submit \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"requests": [{}]}'

2.2ai.batch.status

GET /v1/ai/batch/status/{id}

Query the status, progress and completed/failed count of batch tasks.

Parameters

NameTypeRequiredDescription
batch_idstring
Required
The ID of the target batch task.

Returns

BatchStatus { batch_id, state, progress, total_count, completed_count, failed_count, created_at, total_cost_usd? }
NameTypeDescription
batch_idstringUnique identifier for this batch job
pattern: ^batch_[A-Za-z0-9]{20,}$
state"connecting" | "queued" | "in_progress" | "partial" | "completed" | "failed" | "expired" | "cancelled"Current lifecycle state of this resource
progressnumberProgress of the async operation (0.0 to 1.0)
0–1
total_countintegerTotal number of items across all pages
≥ 0
completed_countintegerNumber of completed items in the batch
≥ 0
failed_countintegerNumber of failed items in the batch
≥ 0
created_atstringISO 8601 timestamp when this resource was created
format: date-time
estimated_completion_atstring | nullEstimated ISO 8601 timestamp when the batch will complete
format: date-time
actual_completion_atstring | nullISO 8601 timestamp when the batch actually completed
format: date-time
total_cost_usdnumber | nullTotal cost of the batch in USD
≥ 0

Example

One-time prep (each example is assumed to be complete):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/ai/batch/status/ID \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.3ai.batch.results

GET /v1/ai/batch/results/{id}

Pull the results of the batch processing task one by one in pages.

Parameters

NameTypeRequiredDescription
batch_idstring
Required
The ID of the target batch task.
cursorstringOptionalPaging cursor: Pass in the next_cursor returned from the previous page to get the next page.
limitnumberOptionalThe maximum number of items returned on a single page.

Returns

BatchResultsPage { items, total_count, next_cursor?, download_url? }
NameTypeDescription
itemsobject[]Array of result items in this page
items[].request_indexintegerIndex in the original requests array.
≥ 0
items[].okbooleanWhether the operation succeeded
items[].resultanyCapability result (ChatResult / EmbeddingResult) when ok=true.
items[].errorobject | nullError message if the operation failed
items[].error.codestringStable identifier from registry.yaml.
items[].error.http_statusintegerHTTP status code of the webhook delivery attempt
400–599
items[].error.messagestringHuman-readable hint.
items[].error.docs_urlstringDocumentation URL for this error code
format: uri
items[].error.code_detailstringSub-classification (e.g. wallet cap reason).
items[].error.retryablebooleanWhether the error is retryable
items[].error.retry_after_msintegerSuggested retry delay in milliseconds
≥ 0
items[].error.paramstringWhich parameter failed validation, if applicable.
items[].error.trace_idstringDistributed tracing identifier
items[].error.request_idstringServer-assigned request identifier for tracing
total_countintegerTotal number of items across all pages
≥ 0
next_cursorstring | nullPass back into results() to fetch the next page. null = end.
download_urlstring | nullBulk download reference for large result sets (JSONL); null when results are inlined.
format: uri

Example

One-time prep (each example is assumed to be complete):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/ai/batch/results/ID \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.4ai.batch.list

GET /v1/ai/batch/list

List all batch processing tasks of this account in pages.

Parameters

NameTypeRequiredDescription
cursorstringOptionalPaging cursor: Pass in the next_cursor returned from the previous page to get the next page.
limitnumberOptionalThe maximum number of items returned on a single page.

Returns

BatchListResult { batches, total_count, next_cursor? }
NameTypeDescription
batchesobject[]List of batch summary objects
batches[].batch_idstringUnique identifier for this batch job
pattern: ^batch_[A-Za-z0-9]{20,}$
batches[].state"connecting" | "queued" | "in_progress" | "partial" | "completed" | "failed" | "expired" | "cancelled"Current lifecycle state of this resource
batches[].progressnumberProgress of the async operation (0.0 to 1.0)
0–1
batches[].total_countintegerTotal number of items across all pages
≥ 0
batches[].completed_countintegerNumber of completed items in the batch
≥ 0
batches[].failed_countintegerNumber of failed items in the batch
≥ 0
batches[].created_atstringISO 8601 timestamp when this resource was created
format: date-time
batches[].estimated_completion_atstring | nullEstimated ISO 8601 timestamp when the batch will complete
format: date-time
batches[].actual_completion_atstring | nullISO 8601 timestamp when the batch actually completed
format: date-time
batches[].total_cost_usdnumber | nullTotal cost of the batch in USD
≥ 0
total_countintegerTotal number of items across all pages
≥ 0
next_cursorstring | nullPass back into list() to fetch the next page. null = end.

Example

One-time prep (each example is assumed to be complete):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/ai/batch/list \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.5ai.batch.cancel

POST /v1/ai/batch/cancel/{id}

Cancel an ongoing batch task.

Parameters

NameTypeRequiredDescription
batch_idstring
Required
The ID of the batch task to cancel.
idempotency_keystringOptionalOptional dedup key; identical retries return the same result.

Returns

BatchStatus { batch_id, state, ... }
NameTypeDescription
batch_idstringUnique identifier for this batch job
pattern: ^batch_[A-Za-z0-9]{20,}$
state"connecting" | "queued" | "in_progress" | "partial" | "completed" | "failed" | "expired" | "cancelled"Current lifecycle state of this resource
progressnumberProgress of the async operation (0.0 to 1.0)
0–1
total_countintegerTotal number of items across all pages
≥ 0
completed_countintegerNumber of completed items in the batch
≥ 0
failed_countintegerNumber of failed items in the batch
≥ 0
created_atstringISO 8601 timestamp when this resource was created
format: date-time
estimated_completion_atstring | nullEstimated ISO 8601 timestamp when the batch will complete
format: date-time
actual_completion_atstring | nullISO 8601 timestamp when the batch actually completed
format: date-time
total_cost_usdnumber | nullTotal cost of the batch in USD
≥ 0

Example

One-time prep (each example is assumed to be complete):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/ai/batch/cancel/ID \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"batch_id": "sample"}'

2.6ai.batch.export

POST /v1/ai/batch/export/{id}

Export the batch results to a jsonl or csv file and return the download task.

Parameters

NameTypeRequiredDescription
batch_idstring
Required
The ID of the batch task to export.
pattern: ^batch_[A-Za-z0-9]{20,}$
format"jsonl" | "csv"OptionalExport file format: jsonl or csv.
default: "jsonl"
conversation_idstringOptionalOptional, export only the results of the specified session.
metadataRecord<string, unknown>OptionalCustom key-value metadata attached to the export task.
idempotency_keystringOptionalOptional dedup key; identical retries return the same result.

Returns

ExportJob { export_id, state, format?, download_url?, expires_at?, created_at }
NameTypeDescription
export_idstringUnique identifier for this export job
pattern: ^exp_[A-Za-z0-9]{20,}$
state"queued" | "in_progress" | "completed" | "failed" | "expired"Current lifecycle state of this resource
format"jsonl" | "csv"Output or input format (e.g. json, csv, png)
default: "jsonl"
download_urlstring | nullPopulated when state=completed.
format: uri
expires_atstring | nullISO 8601 timestamp when this resource or token expires
format: date-time
created_atstringISO 8601 timestamp when this resource was created
format: date-time
errorobject | nullError message if the operation failed
error.codestringStable identifier from registry.yaml.
error.http_statusintegerHTTP status code of the webhook delivery attempt
400–599
error.messagestringHuman-readable hint.
error.docs_urlstringDocumentation URL for this error code
format: uri
error.code_detailstringSub-classification (e.g. wallet cap reason).
error.retryablebooleanWhether the error is retryable
error.retry_after_msintegerSuggested retry delay in milliseconds
≥ 0
error.paramstringWhich parameter failed validation, if applicable.
error.trace_idstringDistributed tracing identifier
error.request_idstringServer-assigned request identifier for tracing

Example

One-time prep (each example is assumed to be complete):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/ai/batch/export/ID \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'

2.7ai.cost.estimate

POST /v1/ai/cost/estimate

Estimate the number of tokens and itemized costs of an AI request before calling.

Parameters

NameTypeRequiredDescription
messagesstring | ChatMessage[]
Required
The message used for estimation, which can be a string or an array of messages.
≥ 1 item
modelstringOptionalExplicit model id; skips task/prefer routing.
default: "openai/gpt-4o"
expected_output_tokensnumberOptionalThe expected number of output tokens, used to estimate the output side cost.
≥ 0default: 500
cache_strategy"vendor" | "infrai" | "none"OptionalWhich cache layer to use.
default: "vendor"
batch_modebooleanOptionalRun as a batch job for a discounted rate.
default: false
toolsTool[]OptionalTool/function-calling definitions.

Returns

CostEstimate { model, vendor, vendor_region?, prompt_tokens, expected_output_tokens, breakdown }
NameTypeDescription
modelstringResolved model_id this estimate is for.
vendorstringVendor that would serve the request.
vendor_region"china" | "western"Region of the serving vendor (drives markup).
prompt_tokensintegerNumber of tokens in the prompt
≥ 0
expected_output_tokensintegerEstimated number of output tokens
≥ 0
breakdownobjectCost breakdown by component
breakdown.currency"USD" | "CNY"ISO 4217 currency code (e.g. USD, CNY)
breakdown.input_costnumberInput token cost in USD
≥ 0
breakdown.output_costnumberOutput token cost in USD
≥ 0
breakdown.markupnumberMarkup applied on top of vendor cost
≥ 0
breakdown.cache_discountnumberDiscount from cache hits in USD
≥ 0
breakdown.batch_discountnumberDiscount for batch processing in USD
≥ 0
breakdown.failover_adjustmentnumberCost adjustment due to vendor failover
breakdown.finalnumberFinal cost after all adjustments in USD
≥ 0

Example

One-time prep (each example is assumed to be complete):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/ai/cost/estimate \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"messages": [{"role": "system"}]}'

2.8ai.cost.compare

POST /v1/ai/cost/compare

Estimate and compare costs on multiple models for the same request.

Parameters

NameTypeRequiredDescription
messagesstring | ChatMessage[]
Required
The message used to compare estimates, which can be a string or an array of messages.
≥ 1 item
modelsstring[]OptionalList of model IDs participating in the cost comparison.
expected_output_tokensnumberOptionalThe expected number of output tokens, used to estimate the output side cost.
≥ 0default: 500
cache_strategy"vendor" | "infrai" | "none"OptionalWhich cache layer to use.
default: "vendor"
batch_modebooleanOptionalRun as a batch job for a discounted rate.
default: false
toolsTool[]OptionalTool/function-calling definitions.

Returns

{ estimates: CostEstimate[] }

Example

One-time prep (each example is assumed to be complete):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/ai/cost/compare \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"messages": [{"role": "system"}]}'

2.9ai.tokens.count

POST /v1/ai/tokens/count

Count the number of input tokens for a group of messages under the specified model.

Parameters

NameTypeRequiredDescription
messagesstring | ChatMessage[]
Required
The message to count the number of tokens can be a string or a message array.
≥ 1 item
modelstringOptionalExplicit model id; skips task/prefer routing.
toolsTool[]OptionalTool/function-calling definitions.

Returns

TokenCountResult { prompt_tokens, model }
NameTypeDescription
prompt_tokensintegerTotal prompt tokens incl. tool-definition overhead.
≥ 0
modelstringTokenizer model the count was computed for.

Example

One-time prep (each example is assumed to be complete):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/ai/tokens/count \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"messages": [{"role": "system"}]}'

2.10ai.image.upscale

POST /v1/ai/image/upscale

Magnify the image by 2x or 4x losslessly.

Parameters

NameTypeRequiredDescription
imagestring
Required
Source image to be enlarged, URL or base64.
e.g. data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==
factor2 | 4OptionalMagnification, 2 or 4.
default: 2
idempotency_keystringOptionalOptional dedup key; identical retries return the same result.

Returns

ImageUpscaleResult { image, original_size, new_size }
NameTypeDescription
imageobjectImage data or reference for processing
image.b64_jsonstringBase64-encoded bytes of the upscaled image (inline; stateless passthrough).
image.widthinteger-
≥ 1
image.heightinteger-
≥ 1
image.mime_typestring-
e.g. image/png
image.image_idstring | nullSet only when the caller passed store:true; null for the default stateless transform.
image.urlstring | nullInfrai CDN URL when stored; null by default.
format: uri
original_sizestringOriginal image dimensions before transformation
e.g. 1024x1024
new_sizestringNew image dimensions after transformation
e.g. 2048x2048

Example

One-time prep (each example is assumed to be complete):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/ai/image/upscale \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="}'

2.11ai.tts.voices

GET /v1/ai/tts/voices

Paginated list of sounds available for text-to-speech.

Parameters

NameTypeRequiredDescription
vendorstringOptionalPin a specific vendor instead of auto-routing.

Returns

VoiceListResult { items, count, next_cursor? }
NameTypeDescription
itemsobject[]Array of result items in this page
items[].voice_idstring-
items[].vendorstring-
items[].namestring | null-
items[].modelstring | nullThe vendor model this voice should be paired with for synthesis.
items[].languagestring | nullBCP-47 language tag.
items[].languagesstring[] | nullSupported languages or locales published by the vendor for this voice.
items[].genderstring | null-
items[].preview_urlstring | null-
format: uri
items[].is_defaultbooleanTrue if this is the vendor's default voice used by synthesize() when none is pinned.
next_cursorstring | nullPass back into voices() to fetch the next page. null = end.
countintegerTotal number of items across all pages
≥ 0

Example

One-time prep (each example is assumed to be complete):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/ai/tts/voices \
  -H "Authorization: Bearer $INFRAI_API_KEY"
Advanced: pin a vendor

By default infrai routes each call to the best available provider — you do not pick a vendor. As an escape hatch, this capability accepts an optional vendor parameter to pin one specific provider. Every live vendor for this capability is available in real time from the discovery endpoint for the capability id — see the discovery API.

GET /v1/discovery/{capability}

ai.image.upscale

ai.tts.voices

3. All capabilities

Every routed capability in this module — the complete public REST contract. The methods above are the guided walkthrough; this index is the full reference.

ai.asrPOST /v1/audio/transcriptions

Speech-to-text — transcribe an audio file (multipart or base64 JSON).

Parameters (4)
NameTypeRequiredDescription
filestringRequiredAudio file to transcribe when using multipart/form-data.
format: binary
model"auto" | "cheapest" | "smartest" | stringOptionalModel to use — either a routing MODE (infrai picks the model for you) or a concrete model id to pin. Modes: 'auto' — Default. Balanced routing across healthy vendors — same tier as `prefer: balanced`.; 'cheapest' — Cheapest healthy model that serves the task — same tier as `prefer: cheapest`.; 'smartest' — Flagship-tier model — same tier as `prefer: smartest`. To pin instead, pass any id a verified vendor serves ('gpt-4o-mini'), or 'vendor/model' ('dashscope/qwen-plus') to pin the vendor too — GET /v1/models returns the live servable set. Omitted or empty behaves as 'auto'.
default: "auto"e.g. auto
languagestringOptionalISO-639-1 language hint.
response_format"json" | "text" | "srt" | "verbose_json" | "vtt"Optional
ai.batch.cancelPOST /v1/ai/batch/cancel/{id}

Cancel an in-progress batch job (idempotent).

Parameters (3)
NameTypeRequiredDescription
idstringRequiredPath parameter.
batch_idstringRequiredId of the batch job to cancel.
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
ai.batch.exportPOST /v1/ai/batch/export/{id}

Export batch results to a JSONL or CSV file and return a download job.

Parameters (6)
NameTypeRequiredDescription
idstringRequiredPath parameter.
batch_idstring | nullOptionalTarget batch for ai.batch.export.
pattern: ^batch_[A-Za-z0-9]{20,}$
conversation_idstring | nullOptionalTarget conversation for ai.chat.history.export; null = all history.
format"jsonl" | "csv"OptionalOutput or input format (e.g. json, csv, png)
default: "jsonl"
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
metadataobject | nullOptionalArbitrary key-value metadata attached to this resource
ai.batch.listGET /v1/ai/batch/list

List all batch jobs on the account with pagination.

No request parameters.

ai.batch.resultsGET /v1/ai/batch/results/{id}

Fetch per-item results of a batch job with pagination.

Parameters (1)
NameTypeRequiredDescription
idstringRequiredPath parameter.
ai.batch.statusGET /v1/ai/batch/status/{id}

Get a batch job's status, progress, and completed/failed counts.

Parameters (1)
NameTypeRequiredDescription
idstringRequiredPath parameter.
ai.batch.submitPOST /v1/ai/batch/submit

Submit a batch of AI requests as one async batch job (billed at cost pass-through with no markup).

Parameters (5)
NameTypeRequiredDescription
requestsobject[]RequiredEach item is a ChatRequest / EmbeddingRequest payload.
≥ 1 item
batch_timeoutstringOptionalMaximum wall-clock the batch may run before expiring.
default: "24h"e.g. 1h
metadataobject | nullOptionalArbitrary key-value metadata attached to this resource
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
storebooleanOptionalOpt in to RETAIN the produced asset/record in Infrai's own store (default false = stateless passthrough: process, return inline, keep nothing). When true, Infrai persists the asset, bills a self-hosted storage line item and applies a retention TTL — and only then do the *.list/get/delete read caps see it.
default: false
ai.chatPOST /v1/chat/completions

Chat completions — text, vision and tool calls, with streaming.

Parameters (8)
NameTypeRequiredDescription
model"auto" | "cheapest" | "smartest" | stringOptionalModel to use — either a routing MODE (infrai picks the model for you) or a concrete model id to pin. Modes: 'auto' — Default. Balanced routing across healthy vendors — same tier as `prefer: balanced`.; 'cheapest' — Cheapest healthy model that serves the task — same tier as `prefer: cheapest`.; 'smartest' — Flagship-tier model — same tier as `prefer: smartest`. To pin instead, pass any id a verified vendor serves ('gpt-4o-mini'), or 'vendor/model' ('dashscope/qwen-plus') to pin the vendor too — GET /v1/models returns the live servable set. Omitted or empty behaves as 'auto'.
default: "auto"e.g. auto
messagesobject[]RequiredOpenAI chat messages: a list of {role, content}.
temperaturenumberOptional
max_tokensintegerOptional
top_pnumberOptional
streambooleanOptionalServer-Sent Events streaming when true.
toolsobject[]Optional
response_formatobjectOptional
ai.cost.comparePOST /v1/ai/cost/compare

Estimate and compare the cost of the same request across multiple models.

Parameters (7)
NameTypeRequiredDescription
messagesobject[]RequiredChat messages to price (same shape as ai.chat); cost is estimated from their token count.
≥ 1 item
modelstring | nullOptionalSingle model to estimate. Used by ai.cost.estimate. Explicit model_id is allowed here (selection semantics).
default: "openai/gpt-4o"
modelsstring[] | nullOptionalModels to compare. Used by ai.cost.compare; result is sorted ascending by final cost.
expected_output_tokensintegerOptionalAssumed completion length for the estimate.
≥ 0default: 500
cache_strategy"vendor" | "infrai" | "none"OptionalCache strategy hint (none, exact, semantic)
default: "vendor"
batch_modebooleanOptionalWhen true, applies the 50% batch discount to the estimate.
default: false
toolsobject[] | nullOptionalTool/function definitions for the model to call
ai.cost.estimatePOST /v1/ai/cost/estimate

Estimate token counts and itemized cost for an AI request before calling it.

Parameters (7)
NameTypeRequiredDescription
messagesobject[]RequiredChat messages to price (same shape as ai.chat); cost is estimated from their token count.
≥ 1 item
modelstring | nullOptionalSingle model to estimate. Used by ai.cost.estimate. Explicit model_id is allowed here (selection semantics).
default: "openai/gpt-4o"
modelsstring[] | nullOptionalModels to compare. Used by ai.cost.compare; result is sorted ascending by final cost.
expected_output_tokensintegerOptionalAssumed completion length for the estimate.
≥ 0default: 500
cache_strategy"vendor" | "infrai" | "none"OptionalCache strategy hint (none, exact, semantic)
default: "vendor"
batch_modebooleanOptionalWhen true, applies the 50% batch discount to the estimate.
default: false
toolsobject[] | nullOptionalTool/function definitions for the model to call
ai.embedPOST /v1/embeddings

Text embeddings for search and RAG.

Parameters (4)
NameTypeRequiredDescription
model"auto" | "cheapest" | "smartest" | stringOptionalModel to use — either a routing MODE (infrai picks the model for you) or a concrete model id to pin. Modes: 'auto' — Default. Balanced routing across healthy vendors — same tier as `prefer: balanced`.; 'cheapest' — Cheapest healthy model that serves the task — same tier as `prefer: cheapest`.; 'smartest' — Flagship-tier model — same tier as `prefer: smartest`. To pin instead, pass any id a verified vendor serves ('gpt-4o-mini'), or 'vendor/model' ('dashscope/qwen-plus') to pin the vendor too — GET /v1/models returns the live servable set. Omitted or empty behaves as 'auto'.
default: "auto"e.g. auto
inputstring | string[]RequiredText string or array of strings to embed.
encoding_format"float" | "base64"Optional
dimensionsintegerOptional
ai.imagePOST /v1/images/generations

Image generation from a text prompt.

Parameters (5)
NameTypeRequiredDescription
model"auto" | "cheapest" | "smartest" | stringOptionalModel to use — either a routing MODE (infrai picks the model for you) or a concrete model id to pin. Modes: 'auto' — Default. Balanced routing across healthy vendors — same tier as `prefer: balanced`.; 'cheapest' — Cheapest healthy model that serves the task — same tier as `prefer: cheapest`.; 'smartest' — Flagship-tier model — same tier as `prefer: smartest`. To pin instead, pass any id a verified vendor serves ('gpt-4o-mini'), or 'vendor/model' ('dashscope/qwen-plus') to pin the vendor too — GET /v1/models returns the live servable set. Omitted or empty behaves as 'auto'.
default: "auto"e.g. auto
promptstringRequiredText prompt describing the image.
nintegerOptional
sizestringOptionalImage size such as '1024x1024'.
response_format"url" | "b64_json"Optional
ai.image.upscalePOST /v1/ai/image/upscale

Upscale an image losslessly by 2x or 4x with an AI model (idempotent). To transform an EXISTING image otherwise use the image.* module.

Parameters (8)
NameTypeRequiredDescription
imagestringRequiredURL / file path / base64 of the source image.
e.g. data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==
factor2 | 4OptionalUpscale factor (e.g. 2 or 4)
default: 2
modelstring | nullOptionalModel identifier to use for generation
vendorstring | nullOptionalVendor that handled or will handle this request
timeout_secondsintegerOptionalMaximum execution time in seconds
1–600default: 120
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
metadataobject | nullOptionalArbitrary key-value metadata attached to this resource
storebooleanOptionalOpt in to RETAIN the produced asset/record in Infrai's own store (default false = stateless passthrough: process, return inline, keep nothing). When true, Infrai persists the asset, bills a self-hosted storage line item and applies a retention TTL — and only then do the *.list/get/delete read caps see it.
default: false
ai.models.getGET /v1/models/{model}

Retrieve one model's details (pricing, context, availability).

Parameters (1)
NameTypeRequiredDescription
modelstringRequiredPath parameter.
ai.models.listGET /v1/models

List every model a verified, routable vendor serves.

No request parameters.

ai.moderationPOST /v1/moderations

Classify whether content violates usage policy.

Parameters (2)
NameTypeRequiredDescription
model"auto" | "cheapest" | "smartest" | stringOptionalModel to use — either a routing MODE (infrai picks the model for you) or a concrete model id to pin. Modes: 'auto' — Default. Balanced routing across healthy vendors — same tier as `prefer: balanced`.; 'cheapest' — Cheapest healthy model that serves the task — same tier as `prefer: cheapest`.; 'smartest' — Flagship-tier model — same tier as `prefer: smartest`. To pin instead, pass any id a verified vendor serves ('gpt-4o-mini'), or 'vendor/model' ('dashscope/qwen-plus') to pin the vendor too — GET /v1/models returns the live servable set. Omitted or empty behaves as 'auto'.
default: "auto"e.g. auto
inputstring | string[]RequiredText string or array of strings to moderate.
ai.rerankPOST /v1/ai/rerank

Reorder a list of candidate documents by relevance to a query, returning each candidate's original index and a vendor relevance score. Real vendor dispatch: Cohere rerank, Qwen/DashScope gte-rerank. Replaces the previous original-order mock.

Parameters (5)
NameTypeRequiredDescription
querystringRequiredSearch query string for reranking
≥ 1 chars
candidatesstring[]RequiredDocuments to score against the query; the response returns them reordered by relevance.
≥ 1 item
top_kintegerOptionalNumber of top results to return
≥ 1default: 10
modelstringOptionalOptional model pin (e.g. rerank-english-v3.0, gte-rerank).
vendor"cohere" | "jina" | "qwen"OptionalOptional vendor pin.
ai.tokens.countPOST /v1/ai/tokens/count

Count input tokens for a set of messages under a given model.

Parameters (3)
NameTypeRequiredDescription
messagesobject[]RequiredChat messages to tokenize (same shape as ai.chat), including tool-definition overhead.
≥ 1 item
modelstring | nullOptionalTokenizer model; null = default. Determines which encoding is used.
toolsobject[] | nullOptionalTool definitions; their serialized overhead is included in the count.
ai.ttsPOST /v1/audio/speech

Text-to-speech — synthesize spoken audio (binary body).

Parameters (5)
NameTypeRequiredDescription
model"auto" | "cheapest" | "smartest" | stringOptionalModel to use — either a routing MODE (infrai picks the model for you) or a concrete model id to pin. Modes: 'auto' — Default. Balanced routing across healthy vendors — same tier as `prefer: balanced`.; 'cheapest' — Cheapest healthy model that serves the task — same tier as `prefer: cheapest`.; 'smartest' — Flagship-tier model — same tier as `prefer: smartest`. To pin instead, pass any id a verified vendor serves ('gpt-4o-mini'), or 'vendor/model' ('dashscope/qwen-plus') to pin the vendor too — GET /v1/models returns the live servable set. Omitted or empty behaves as 'auto'.
default: "auto"e.g. auto
inputstringRequiredThe text to synthesize.
voicestringRequiredVoice id such as 'alloy'.
response_formatstringOptionalAudio format such as 'mp3' or 'wav'.
speednumberOptional
ai.tts.voicesGET /v1/ai/tts/voices

List available text-to-speech voices with pagination.

No request parameters.

ai.voice.sessionPOST /v1/ai/voice/session

Mint a short-lived token for an AI realtime VOICE/multimodal conversation session (e.g. OpenAI Realtime). NOT pub/sub channel auth — see realtime.token.issue.

Parameters (6)
NameTypeRequiredDescription
modelstring | nullOptionalRealtime voice model; null lets the server pick a default.
voicestring | nullOptionalVoice id/name to use for the session.
vendorstring | nullOptionalPin to a specific vendor; disables failover.
instructionsstring | nullOptionalSystem instructions for the realtime session.
modalitiesstring[] | nullOptionalEnabled modalities (e.g. text, audio).
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry

4. End-to-end example

A production-style walkthrough of this module: configure once, then run the flow. It exercises most of the module's APIs.

A copy-paste-runnable single-file Python program (stdlib only, no SDK): set your INFRAI_API_KEY, run it, and walk this module's core flow with REAL billed calls — later steps reuse real fields returned by earlier ones. The 12-line helper is the entire integration.

python
#!/usr/bin/env python3
"""Infrai · ai-runtime — runnable real-app example (single file, zero deps).

Copy this file, set your key, run it: every step is a REAL call to
api.infrai.cc, billed at the real (tiny) per-call price, printing the
live JSON response. Get a key at https://infrai.cc/login (Google/
GitHub sign-in grants $2 free credit); add funds at
https://infrai.cc/billing. No SDK — the 12-line helper below is the
entire integration."""
import json
import os
from urllib import error, request

KEY = os.environ.get("INFRAI_API_KEY") or "ifr_..."  # <- your key
BASE = "https://api.infrai.cc"


# Same raw HTTPS POST/GET as every per-method example on this page —
# wrapped once for reuse. There is nothing else to it: no SDK.
def infrai(method, path, body=None):
    req = request.Request(
        BASE + path, method=method,
        data=json.dumps(body).encode() if body is not None else None,
        headers={"Authorization": f"Bearer {KEY}",
                 "Content-Type": "application/json"})
    try:
        with request.urlopen(req, timeout=60) as r:
            return json.loads(r.read())
    except error.HTTPError as e:
        return json.loads(e.read())


def show(label, resp):
    print(f"\n== {label} ==")
    print(json.dumps(resp, indent=2, ensure_ascii=False))
    return resp


# 1) chat — POST /v1/chat/completions (OpenAI-compatible)
ask1 = input("Ask the model anything: ").strip()
r1 = show("chat", infrai("POST", "/v1/chat/completions", {"model":"auto","messages":[{"role":"user","content":ask1}]}))

# 2) embeddings — POST /v1/embeddings (OpenAI-compatible)
r2 = show("embeddings", infrai("POST", "/v1/embeddings", {"model":"auto","input":"Infrai is the standard library for AI-built apps."}))

# 3) ai.cost.estimate — POST /v1/ai/cost/estimate · Estimate token counts and itemized cost for an AI request before calling it.
r3 = show("ai.cost.estimate", infrai("POST", "/v1/ai/cost/estimate", {"messages":[{"role":"system"}]}))

5. Developer guides

Move from endpoint details to complete workflows, production patterns and troubleshooting guides verified against the live API.

AI Runtime developer guides