DEV Community

Phil IPS
Phil IPS

Posted on

How to Use Unorouter API for Text Generation

How to Use Unorouter API for Text Generation

Unorouter provides a simple, low‑cost API for generating text with advanced language models. This tutorial shows you how to call the API and integrate the response into your own applications.

Prerequisites

  • An API key from Unorouter (obtainable from your dashboard).
  • curl installed on your system (or any HTTP client).

Example Request

curl -X POST https://api.unorouter.com/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3.6-flash:free",
    "messages": [
      {"role": "user", "content": "Write a short story about a brave cat."}
    ],
    "temperature": 0.7,
    "max_tokens": 150
  }'
Enter fullscreen mode Exit fullscreen mode

Response

The API returns a JSON object:

{
  "id": "chatcm_12345",
  "object": "chat.completion",
  "created": 1721234567,
  "model": "gemini-3.6-flash:free",
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "Once upon a time, a sleek cat named Luna..."
      },
      "index": 0,
      "logprobs": null,
      "finish_reason": "stop"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Integrating the Response

Parse the JSON to extract choices[0].message.content. You can then display this text in your UI, store it, or further process it.

Tips for Better Results

  • Temperature: Lower values (0.2‑0.5) give more deterministic output; higher values (0.7‑1.0) increase creativity.
  • Max Tokens: Set a reasonable limit to control cost and response length.
  • Model Choice: Use the free tier (gemini-3.6-flash:free) for quick experiments; upgrade for higher quality.

Conclusion

Unorouter’s API makes text generation accessible with just a few lines of code. Experiment with prompts, models, and parameters to tailor outputs to your needs.

Top comments (0)