# Completions

## Create a completion

> Creates a completion for the provided prompt and parameters. Supports both streaming and non-streaming modes.

```json
{"openapi":"3.0.3","info":{"title":"Create a completion","version":"endpoint_completions.createCompletions"},"servers":[{"url":"https://app.interactive.ai/api/v1","description":"Interactive AI API server"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT","description":"API key as bearer token in Authorization header"}},"schemas":{"CompletionResponse":{"type":"object","properties":{"id":{"type":"string"},"object":{"type":"string","enum":["text_completion"]},"created":{"type":"number","format":"double"},"model":{"type":"string"},"provider":{"type":"string"},"system_fingerprint":{"type":"string"},"choices":{"type":"array","items":{"$ref":"#/components/schemas/CompletionChoice"}},"usage":{"$ref":"#/components/schemas/CompletionUsage"}},"required":["id","object","created","model","choices"]},"CompletionChoice":{"type":"object","properties":{"text":{"type":"string"},"index":{"type":"number","format":"double"},"logprobs":{"nullable":true,"oneOf":[{"$ref":"#/components/schemas/CompletionLogprobs"}]},"finish_reason":{"$ref":"#/components/schemas/CompletionFinishReason"},"native_finish_reason":{"type":"string"},"reasoning":{"type":"string","nullable":true}},"required":["text","index","logprobs","finish_reason"]},"CompletionLogprobs":{"type":"object","properties":{"tokens":{"type":"array","items":{"type":"string"}},"token_logprobs":{"type":"array","items":{"type":"number","format":"double"}},"top_logprobs":{"type":"array","nullable":true,"items":{"type":"object","additionalProperties":{"type":"number","format":"double"}}},"text_offset":{"type":"array","items":{"type":"number","format":"double"}}},"required":["tokens","token_logprobs","top_logprobs","text_offset"]},"CompletionFinishReason":{"type":"string","enum":["stop","length","content_filter"]},"CompletionUsage":{"type":"object","properties":{"prompt_tokens":{"type":"number","format":"double"},"completion_tokens":{"type":"number","format":"double"},"total_tokens":{"type":"number","format":"double"}},"required":["prompt_tokens","completion_tokens","total_tokens"]},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string","description":"An error code"},"message":{"type":"string","description":"A human-readable error message"},"param":{"type":"string","description":"The parameter that caused the error, if applicable"},"type":{"type":"string","description":"The type of error"}},"required":["code","message","param","type"]}},"required":["error"]},"CompletionCreateParams":{"type":"object","properties":{"model":{"$ref":"#/components/schemas/ModelName"},"models":{"type":"array","items":{"$ref":"#/components/schemas/ModelName"}},"prompt":{"$ref":"#/components/schemas/CompletionCreateParamsPrompt"},"best_of":{"type":"integer","nullable":true},"echo":{"type":"boolean","nullable":true},"frequency_penalty":{"type":"number","nullable":true,"format":"double"},"logit_bias":{"type":"object","nullable":true,"additionalProperties":{"type":"number","format":"double"}},"logprobs":{"type":"integer","nullable":true},"max_tokens":{"type":"integer","nullable":true},"n":{"type":"integer","nullable":true},"presence_penalty":{"type":"number","nullable":true,"format":"double"},"seed":{"type":"integer","nullable":true},"stop":{"nullable":true,"oneOf":[{"$ref":"#/components/schemas/CompletionCreateParamsStop"}]},"stream":{"type":"boolean","default":false},"stream_options":{"nullable":true,"oneOf":[{"$ref":"#/components/schemas/CompletionCreateParamsStreamOptions"}]},"suffix":{"type":"string","nullable":true},"temperature":{"type":"number","nullable":true,"format":"double"},"top_p":{"type":"number","nullable":true,"format":"double"},"user":{"type":"string"},"metadata":{"type":"object","nullable":true,"additionalProperties":{"type":"string"}},"response_format":{"nullable":true,"oneOf":[{"$ref":"#/components/schemas/CompletionCreateParamsResponseFormat"}]}},"required":["prompt"]},"ModelName":{"type":"string"},"CompletionCreateParamsPrompt":{"oneOf":[{"type":"string"},{"type":"array","items":{"type":"string"}},{"type":"array","items":{"type":"number","format":"double"}},{"type":"array","items":{"type":"array","items":{"type":"number","format":"double"}}}]},"CompletionCreateParamsStop":{"oneOf":[{"type":"string"},{"type":"array","items":{"type":"string"}}]},"CompletionCreateParamsStreamOptions":{"type":"object","properties":{"include_usage":{"type":"boolean","nullable":true}}},"CompletionCreateParamsResponseFormat":{"oneOf":[{"$ref":"#/components/schemas/CompletionCreateParamsResponseFormat0"},{"$ref":"#/components/schemas/CompletionCreateParamsResponseFormat1"},{"$ref":"#/components/schemas/ResponseFormatJSONSchema"},{"$ref":"#/components/schemas/ResponseFormatTextGrammar"},{"$ref":"#/components/schemas/CompletionCreateParamsResponseFormat4"}]},"CompletionCreateParamsResponseFormat0":{"type":"object","properties":{"type":{"type":"string","enum":["text"]}},"required":["type"]},"CompletionCreateParamsResponseFormat1":{"type":"object","properties":{"type":{"type":"string","enum":["json_object"]}},"required":["type"]},"ResponseFormatJSONSchema":{"type":"object","properties":{"type":{"type":"string","enum":["json_schema"]},"json_schema":{"$ref":"#/components/schemas/JSONSchemaConfig"}},"required":["type","json_schema"]},"JSONSchemaConfig":{"type":"object","properties":{"name":{"type":"string"},"description":{"type":"string"},"schema":{"type":"object","additionalProperties":{"description":"Any type"}},"strict":{"type":"boolean","nullable":true}},"required":["name"]},"ResponseFormatTextGrammar":{"type":"object","properties":{"type":{"type":"string","enum":["grammar"]},"grammar":{"type":"string"}},"required":["type","grammar"]},"CompletionCreateParamsResponseFormat4":{"type":"object","properties":{"type":{"type":"string","enum":["python"]}},"required":["type"]}}},"paths":{"/completions":{"post":{"operationId":"create-completions","summary":"Create a completion","description":"Creates a completion for the provided prompt and parameters. Supports both streaming and non-streaming modes.","tags":[["subpackage_completions"]],"parameters":[],"responses":{"200":{"description":"Successful completion response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CompletionResponse"}}}},"400":{"description":"Bad request - invalid parameters","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized - invalid API key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Too many requests - rate limit exceeded","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"requestBody":{"description":"Completion request parameters","required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CompletionCreateParams"}}}}}}}}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.interactive.ai/llm-router/api-reference/completions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
