Skip to content

Your first request ​

The examples below cover three common requests. Set API_BASE and MODELFOLD_API_KEY before running them.

bash
export API_BASE="https://modelfold.ai/v1"   # Production API base URL
export MODELFOLD_API_KEY="mf-..."

Image generation ​

bash
curl -X POST "$API_BASE/images/generations" \
  -H "Authorization: Bearer $MODELFOLD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nano-banana-2",
    "prompt": "a paper boat drifting down a rainy street, cinematic lighting",
    "resolution": "1K"
  }'
FieldRequiredDescription
modelYesImage model ID; see Image models
promptYesPrompt string, up to 2,000 characters
image_urlNoReference image URL for image-to-image or editing models
resolutionNoResolution tier

Response:

json
{
  "ok": true,
  "created": 1792134000,
  "data": [{ "url": "https://.../result.png" }],
  "usage": { "credits": 8, "balance": 992, "latencyMs": 4310 }
}

Video generation ​

bash
curl -X POST "$API_BASE/videos/generations" \
  -H "Authorization: Bearer $MODELFOLD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kling-2.6/text-to-video",
    "prompt": "a paper boat drifting down a rainy street",
    "duration": 5,
    "resolution": "720p"
  }'

Video requests use the same fields as image requests, with duration (seconds) and resolution for video settings. See Video models for available models.

Chat completions ​

The chat API is compatible with OpenAI's chat/completions format:

bash
curl -X POST "$API_BASE/chat/completions" \
  -H "Authorization: Bearer $MODELFOLD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-6",
    "messages": [{ "role": "user", "content": "用两句话解释扩散模型在做什么" }],
    "max_tokens": 512
  }'
FieldRequiredDescription
modelYesChat model ID; see Chat models
messagesYesNon-empty array of objects such as { "role": "user", "content": "..." }
max_tokensNoDefaults to 1024; used to estimate the credit reservation
temperatureNoSampling temperature

Response:

json
{
  "ok": true,
  "object": "chat.completion",
  "model": "claude-sonnet-4-6",
  "choices": [{ "index": 0, "message": { "role": "assistant", "content": "..." }, "finish_reason": "stop" }],
  "usage": { "input_tokens": 18, "output_tokens": 96, "credits": 1, "balance": 991 }
}

Chat is billed by token usage. usage.credits is the final charge after settlement, which may differ from the initial reservation.

Error handling ​

Errors use a consistent response structure:

json
{ "ok": false, "error": { "type": "insufficient_credits", "message": "积分不足:需要 18,当前 5" } }
HTTPerror.typeMeaning and action
400unsupported_modelUnknown model or endpoint mismatch, such as a chat model sent to the image endpoint
400invalid_promptMissing prompt or more than 2,000 characters
400invalid_messagesMissing messages or an empty array
401unauthorizedInvalid or revoked key
402insufficient_creditsInsufficient balance; no provider call or charge was made
429rate_limitedRate limit exceeded
502upstream_failedProvider call failed; credits have been refunded automatically
503upstream_unavailableThe provider for this model has not been configured

Next steps ​

ModelFold — one API for all the best AI models.