Create a text completion

Create a text completion from the provided prompt

POST /v1/completions

Service root: https://getrouter.ai

Protocol: OpenAI Completions

Authentication: Authorization: Bearer YOUR_API_KEY

Request body

The request body is required. Media type: application/json

Request fields

FieldTypeRequiredDescription
modelstringYes
promptstring or array<string>Yes
max_tokensintegerNo
temperaturenumberNo
top_pnumberNo
nintegerNo
streambooleanNo
stopstring or array<string>No
suffixstringNo
echobooleanNo

Example request

curl --request POST \
  --url https://getrouter.ai/v1/completions \
  --header "Authorization: Bearer YOUR_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
  "model": "MODEL_ID",
  "prompt": "A futuristic city at sunset",
  "stream": false,
  "temperature": 1,
  "max_tokens": 1
}'

Responses

StatusDescription
200Response created successfully

Success response fields

FieldTypeRequiredDescription
idstringNo
objectstringNo
createdintegerNo
modelstringNo
choicesarray<object>No
usageobjectNo

Example response

{
  "id": "string",
  "object": "object",
  "created": 1,
  "model": "MODEL_ID",
  "choices": [
    {
      "text": "string",
      "index": 1,
      "finish_reason": "string"
    }
  ],
  "usage": {
    "prompt_tokens": 1,
    "completion_tokens": 1,
    "total_tokens": 1,
    "prompt_tokens_details": {
      "cached_tokens": 1,
      "text_tokens": 1,
      "audio_tokens": 1,
      "image_tokens": 1
    },
    "completion_tokens_details": {
      "text_tokens": 1,
      "audio_tokens": 1,
      "reasoning_tokens": 1
    }
  }
}

This page is generated from the public Relay OpenAPI specification. Browse the complete specification in the API Explorer.