Skip to content
dhanu docs
Browse pages

API reference

Generate text

POST /api/pub/v1/text — generate text from a prompt, with an optional system instruction and token cap.

POST https://api.dhanu.ai/api/pub/v1/text

Generates text from a prompt. Nothing is stored — no task, no document, no version history. You get the text back and a metering record is written against the acting project.

Request

FieldTypeRequiredNotes
promptstringYesUp to 2000 characters
systemstringNoSystem instruction shaping the reply
maxTokensnumberNoCaps the length of the reply
projectIdstringNoRequired when the key is scoped to more than one project
curl -X POST https://api.dhanu.ai/api/pub/v1/text \
  -H "Authorization: Bearer $DHANU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Write a haiku about Kathmandu",
    "system": "You are a concise poet.",
    "maxTokens": 200
  }'

Response

201 Created

{
  "text": "…",
  "model": "…",
  "usage": { "inputTokens": 12, "outputTokens": 41 },
  "cost": { "amount": 28, "currency": "NPR" }
}

cost.amount is in the currency’s minor unit, so 28 is NPR 0.28. A reply of roughly 500 tokens in and 500 out costs on the order of 28 paisa.

Errors

CodeStatusMeaning
invalid_generation_prompt422Prompt is empty or over 2000 characters
project_id_required422Multi-project key called without projectId
insufficient_credits402Workspace credit balance is zero or below

The full list is on Errors.