Skip to main content
POST
/
generate
/
text
Generate text
curl --request POST \
  --url https://api.horizon.new/v1/generate/text \
  --header 'Content-Type: application/json' \
  --data '{
  "prompt": "<string>",
  "model": "sonnet",
  "maxTokens": 800,
  "temperature": 0.7,
  "metadata": {}
}'
{
  "jobId": "job_01hx9q9",
  "content": "<string>",
  "usage": {
    "promptTokens": 123,
    "completionTokens": 123,
    "totalTokens": 123
  }
}
Produce short- or long-form text with Horizon’s tuned language models. Use this endpoint for copywriting, summaries, or scripted dialog you plan to surface in apps, emails, or support workflows.

Request body

  • prompt — Required instructions or seed text.
  • model — Optional model identifier; defaults to the workspace text model (e.g., sonnet).
  • maxTokens — Optional upper bound for the completion length; defaults to 800.
  • temperature — Optional float between 0 and 1; higher values increase creativity.
  • metadata — Optional object that attaches custom keys for downstream auditing.

Sample request

curl https://api.horizon.new/v1/generate/text \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Write a friendly welcome line for new Horizon users joining the platform.",
    "temperature": 0.2,
    "metadata": {
      "campaign": "spring-launch",
      "locale": "en-US"
    }
  }'

Response

Returns 200 OK with the generated text in result.content, token usage metrics under result.usage, and the deterministic jobId that you can reference in logs or attach to downstream automations.

Tips

  • Set temperature below 0.3 when you need repeatable copy for approval workflows.
  • If you need streaming output, append ?stream=true to the request and consume the server-sent events feed.
  • Even when responses return synchronously, you can retrieve the job later via GET /jobs/{jobId} for auditing or replay.

x402 flow

Text generation is priced via Coinbase’s x402 protocol. On unpaid requests Horizon returns 402 Payment Required with a PaymentRequiredResponse payload. Example:
HTTP/1.1 402 Payment Required
Content-Type: application/json

{
  "x402Version": 1,
  "accepts": [
    {
      "scheme": "exact",
      "network": "base-sepolia",
      "maxAmountRequired": "50000",                // $0.05 in 6‑decimal USDC
      "resource": "POST /generate/text",
      "description": "Horizon text generation",
      "mimeType": "application/json",
      "payTo": "0xYourReceivingWallet",
      "maxTimeoutSeconds": 90,
      "asset": "0xYourUSDCContract",
      "extra": {
        "name": "USDC",
        "version": "1"
      }
    }
  ],
  "error": null
}
Resolve the challenge by following the Coinbase spec:
  1. Send the accepts entry to your facilitator as outlined in Client & server responsibilities.
  2. Use the facilitator to verify and settle the payment (POST /verify, POST /settle). You receive a Base64 Payment Payload.
  3. Retry the original request including the payload in an X-PAYMENT header:
    curl https://api.horizon.new/v1/generate/text \
      -H "Content-Type: application/json" \
      -H "X-PAYMENT: eyJ4NDAyVmVyc2lvbiI6MSwic2NoZW1lIjoiZXhhY3QiLC4uLn0=" \
      -d '{ ...original body... }'
    
  4. Horizon validates the payment (locally or through the facilitator) and resumes processing. Successful responses can include X-PAYMENT-RESPONSE with the settlement receipt.
Need a refresher? Start with the Quickstart for sellers before rolling this endpoint to production.

Body

application/json
prompt
string
required
model
string
Example:

"sonnet"

maxTokens
integer
default:800
Required range: 1 <= x <= 4000
temperature
number
default:0.7
Required range: 0 <= x <= 1
metadata
object

Response

Generated text

jobId
string
required
Example:

"job_01hx9q9"

content
string
required
usage
object