completions
Create text completion
Section titled “Create text completion”Create a text completion, supports streaming
Request
Section titled “Request”POST /completionsRequest Body
Section titled “Request Body”| Field | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model name |
| prompt | string | Yes | Prompt text |
| best_of | integer | No | Generate multiple results and return the best one |
| echo | boolean | No | Whether to echo the prompt |
| frequency_penalty | number | No | - |
| logit_bias | object | No | - |
| max_tokens | integer | No | - |
| n | integer | No | - |
| presence_penalty | number | No | - |
| seed | integer | No | - |
| stop | string | No | - |
| stream | boolean | No | - |
| temperature | number | No | - |
| top_p | number | No | - |
| user | string | No | - |
Request Examples
Section titled “Request Examples”Simple text completion
Section titled “Simple text completion”{ "model": "gpt-4o-mini", "prompt": "Once upon a time", "max_tokens": 50}Completion with options
Section titled “Completion with options”{ "model": "qwen-plus", "prompt": "Write a haiku about coding", "max_tokens": 100, "temperature": 0.8, "top_p": 1, "n": 1}Streaming completion
Section titled “Streaming completion”{ "model": "gpt-4o-mini", "prompt": "List 3 benefits of unit testing", "max_tokens": 64, "stream": true, "stop": [ "\n\n" ]}Code completion example
Section titled “Code completion example”{ "model": "qwen3-coder-plus", "prompt": "def fibonacci(n):", "max_tokens": 80, "temperature": 0.3, "top_p": 0.9}Successful response
Response Schema
Section titled “Response Schema”| Field | Type | Required | Description |
|---|---|---|---|
| id | string | Yes | - |
| object | string | Yes | - |
| created | integer | Yes | - |
| model | string | Yes | - |
| choices | Array<CompletionChoice> | Yes | - |
| usage | object | No | - |
Response Example
Section titled “Response Example”{ "id": "cmpl-123", "object": "completion", "created": 1677652288, "model": "gpt-4o-mini", "choices": [ { "text": ", there was a young programmer who loved to code.", "index": 0, "logprobs": null, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 5, "completion_tokens": 12, "total_tokens": 17 }}Code Examples
Section titled “Code Examples”JavaScript (Fetch)
Section titled “JavaScript (Fetch)”const response = await fetch('https://api.r9s.ai/v1/completions', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify({ "model": "gpt-4o-mini", "prompt": "Once upon a time", "max_tokens": 50})});
const data = await response.json();console.log(data);Python (requests)
Section titled “Python (requests)”import requests
url = "https://api.r9s.ai/v1/completions"headers = { "Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json"}
response = requests.post(url, json={ "model": "gpt-4o-mini", "prompt": "Once upon a time", "max_tokens": 50}, headers=headers)data = response.json()print(data)curl -X POST "https://api.r9s.ai/v1/completions" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model":"gpt-4o-mini","prompt":"Once upon a time","max_tokens":50}'Schema Reference
Section titled “Schema Reference”CompletionRequest
Section titled “CompletionRequest”| Field | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model name |
| prompt | string | Yes | Prompt text |
| best_of | integer | No | Generate multiple results and return the best one |
| echo | boolean | No | Whether to echo the prompt |
| frequency_penalty | number | No | - |
| logit_bias | object | No | - |
| max_tokens | integer | No | - |
| n | integer | No | - |
| presence_penalty | number | No | - |
| seed | integer | No | - |
| stop | string | No | - |
| stream | boolean | No | - |
| temperature | number | No | - |
| top_p | number | No | - |
| user | string | No | - |
CompletionResponse
Section titled “CompletionResponse”| Field | Type | Required | Description |
|---|---|---|---|
| id | string | Yes | - |
| object | string | Yes | - |
| created | integer | Yes | - |
| model | string | Yes | - |
| choices | Array<CompletionChoice> | Yes | - |
| usage | object | No | - |
CompletionChoice
Section titled “CompletionChoice”| Field | Type | Required | Description |
|---|---|---|---|
| text | string | Yes | - |
| index | integer | Yes | - |
| logprobs | object | No | - |
| finish_reason | string (stop, length, content_filter) | Yes | - |
| Field | Type | Required | Description |
|---|---|---|---|
| prompt_tokens | integer | Yes | Number of tokens in the prompt (input) |
| prompt_tokens_details | object | No | Details about prompt tokens |
| completion_tokens | integer | Yes | Number of tokens in the completion (output) |
| completion_tokens_details | object | No | Details about completion tokens |
| total_tokens | integer | Yes | Total number of tokens (prompt + completion) |
Related APIs
Section titled “Related APIs”- API Overview - Learn about authentication and basic information
- models - View models related APIs
- chat - View chat related APIs
- responses - View responses related APIs
- messages - View messages related APIs
- edits - View edits related APIs
- images - View images related APIs
- embeddings - View embeddings related APIs
- engine-embeddings - View engine-embeddings related APIs
- moderations - View moderations related APIs
- audio - View audio related APIs
- search - View search related APIs
- proxy - View proxy related APIs