Text Generation
With the LivRouter API, you can use LLMs to generate any text - from code and mathematical expressions to structured JSON or human-like text.
Requests are built from a messages array: each entry carries a role (system for instructions, user for prompts, assistant for prior replies) and its content. Multi-turn conversations are just the same array with the history included — the model sees the whole list, so you control context and spend by deciding what to keep. Optional parameters like temperature work as in the OpenAI SDK because the request format is the same.
Toggle between the Chat Completions API (/chat/completions, message-array input) and the Responses API (/responses, string or structured input). Both hit the same https://api.livrouter.com/v1 endpoint with the same key; pick whichever your SDK or codebase already targets.
from openai import OpenAI client = OpenAI( base_url="https://api.livrouter.com/v1") response = client.chat.completions.create( model="gpt-6-sol", messages=[ {"role": "user", "content": "Summarize this: [long text]"} ], temperature=0.7) print(response.choices[0].message.content)Chat Completions fields
| Field | Requirement | Notes |
|---|---|---|
| model | Required string | Use the exact accessible model ID from the current catalog. |
| messages | Required array | Ordered messages with role and content. Include the conversation history you need. |
| stream | Optional boolean | Receive incremental Chat Completions chunks when true. |
| max_completion_tokens / max_tokens | Model dependent | Use the output-limit field supported by the selected model. |
| temperature | Model dependent | Omit this parameter if the selected model rejects sampling controls. |
| tools / tool_choice | Capability dependent | Requires tool support; your application executes the requested function. |
For a dedicated protocol walkthrough, see Responses or Messages. These protocols use different input and output structures.
Read the response
For Chat Completions, read choices[0].message.content and inspect finish_reason for a complete response, a token limit, or a tool request. A tool call may have no text content. The Quickstart shows an illustrative JSON response and how to verify the recorded charge.
Streaming
Both request styles support streaming responses: add "stream": true and read the response as server-sent events as they are produced, instead of waiting for the full completion. With cURL, the -N flag disables buffering so chunks print as they arrive:
curl -N https://api.livrouter.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -d '{ "model": "gpt-6-sol", "stream": true, "messages": [{"role": "user", "content": "Write a short release note."}] }'The SDKs expose the same flag as stream=True (Python) or stream: true (JavaScript) and return an iterator of chunks; accumulate delta content as it arrives. Every request — streamed or not — appears in your dashboard usage logs with the model that served it, so you can verify spend right after testing.
For models that expose their reasoning, see the Reasoning guide; for connecting chat frontends like SillyTavern, see Integrations.