Completions - Python SDK

Completions method reference

(completions)

Overview

Available Operations

generate

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

Example Usage

1from openrouter import OpenRouter
2import os
3
4with OpenRouter(
5 api_key=os.getenv("OPENROUTER_API_KEY", ""),
6) as open_router:
7
8 res = open_router.completions.generate(prompt=[], stream=False)
9
10 # Handle response
11 print(res)

Parameters

ParameterTypeRequiredDescription
promptcomponents.Prompt✔️N/A
modelOptional[str]N/A
modelsList[str]N/A
best_ofOptionalNullable[int]N/A
echoOptionalNullable[bool]N/A
frequency_penaltyOptionalNullable[float]N/A
logit_biasDict[str, float]N/A
logprobsOptionalNullable[int]N/A
max_tokensOptionalNullable[int]N/A
nOptionalNullable[int]N/A
presence_penaltyOptionalNullable[float]N/A
seedOptionalNullable[int]N/A
stopOptionalNullable[components.CompletionCreateParamsStop]N/A
streamOptional[bool]N/A
stream_optionsOptionalNullable[components.StreamOptions]N/A
suffixOptionalNullable[str]N/A
temperatureOptionalNullable[float]N/A
top_pOptionalNullable[float]N/A
userOptional[str]N/A
metadataDict[str, str]N/A
response_formatOptionalNullable[components.CompletionCreateParamsResponseFormatUnion]N/A
retriesOptional[utils.RetryConfig]Configuration to override the default retry behavior of the client.

Response

components.CompletionResponse

Errors

Error TypeStatus CodeContent Type
errors.ChatError400, 401, 429application/json
errors.ChatError500application/json
errors.OpenRouterDefaultError4XX, 5XX*/*