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
| Field | Type | Required | Notes |
|---|---|---|---|
prompt | string | Yes | Up to 2000 characters |
system | string | No | System instruction shaping the reply |
maxTokens | number | No | Caps the length of the reply |
projectId | string | No | Required 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
| Code | Status | Meaning |
|---|---|---|
invalid_generation_prompt | 422 | Prompt is empty or over 2000 characters |
project_id_required | 422 | Multi-project key called without projectId |
insufficient_credits | 402 | Workspace credit balance is zero or below |
The full list is on Errors.