Login
API Reference

Text Generation

Generate chat completions and long-form content.

All documentation

Generate chat completions, articles, code, summaries, and more with type: "text" (the default).

Request

POST /api/external/ai
Content-Type: application/json
X-API-Key: your-api-key-here

Simple prompt

{
  "prompt": "Explain machine learning in simple terms",
  "model": "abzar-ai",
  "type": "text",
  "max_tokens": 1000,
  "temperature": 0.7
}

Prompt + system instruction

{
  "system": "You are a concise technical writer.",
  "prompt": "Explain machine learning in simple terms",
  "model": "abzar-ai",
  "type": "text"
}

Chat messages

{
  "type": "text",
  "model": "abzar-ai",
  "messages": [
    { "role": "system", "content": "You are a helpful coding assistant." },
    { "role": "user", "content": "Write a Python hello world." },
    { "role": "assistant", "content": "print(\"Hello, world\")" },
    { "role": "user", "content": "Now add a main guard." }
  ],
  "max_tokens": 500,
  "temperature": 0.2
}

Provide either prompt or a non-empty messages array (or both patterns above). Roles must be system, user, or assistant.

Parameters

ParameterTypeDefaultDescription
promptstring—User prompt (required unless messages is provided)
messagesarray—Chat history; each item { role, content }
systemstring—Optional system message when using prompt
modelstring—Required. Model id or name from GET discovery
providerstringmodel’s providerMust match the resolved model provider if set
typestringtextMust be text for this flow
max_tokensnumbercappedMax output tokens (clamped to model + platform limits)
temperaturenumberprovider defaultRandomness from 0.0 to 2.0
streambooleanfalseWhen true, returns SSE if the model supports streaming

Temperature guidance

Use caseSuggested range
Code generation0.1 – 0.3
Technical writing0.3 – 0.5
General content0.5 – 0.8
Creative writing0.7 – 1.2
Brainstorming1.0 – 1.5

Streaming (SSE)

Set "stream": true only when the chosen model reports capabilities.streaming: true (or supported_features.streaming is true for your key/catalog).

  • Response Content-Type is an SSE stream (OpenAI-style chunk framing for text)
  • Token usage is tracked when the stream completes
  • Image and embedding requests reject stream: true

Success response (non-stream)

{
  "success": true,
  "data": {
    "content": "Machine learning is a subset of artificial intelligence...",
    "model": "abzar-ai",
    "tokens_used": 150,
    "actual_tokens": 148,
    "cost": 0.0003,
    "remaining_tokens": 9850,
    "usage_percentage": "1.5"
  }
}
FieldDescription
contentGenerated text
tokens_usedTokens deducted from your balance
actual_tokensProvider-reported token usage when available
remaining_tokensBalance after this request
usage_percentagePercent of plan/credit usage consumed

Example prompts

Creative writing

{
  "prompt": "Write a short story about a robot discovering emotions",
  "model": "abzar-ai",
  "type": "text",
  "max_tokens": 1500,
  "temperature": 0.9
}

Code generation

{
  "prompt": "Create a Python function to calculate the Fibonacci sequence",
  "model": "abzar-ai",
  "type": "text",
  "max_tokens": 500,
  "temperature": 0.1
}

Summarization

{
  "prompt": "Summarize the key benefits of renewable energy in 3 bullet points",
  "model": "abzar-ai",
  "type": "text",
  "max_tokens": 200,
  "temperature": 0.3
}

Replace example model names with values from your live GET response.

Requirements

  • Valid API key (pk_…)
  • Sufficient remaining tokens/credits
  • Provider available and allowed on your API key
  • Model available and allowed on your API key

If tokens are insufficient, the API returns 402 with required vs remaining token details.