Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Openai Openai python Completion Create Params

From Leeroopedia
Knowledge Sources
Domains API_Types, Python
Last Updated 2026-02-15 00:00 GMT

Overview

Concrete type for legacy completion creation parameters provided by the openai-python SDK.

Description

The CompletionCreateParams is a Union type alias of CompletionCreateParamsNonStreaming and CompletionCreateParamsStreaming, both extending a shared CompletionCreateParamsBase TypedDict. The base type defines all parameters for the legacy completions endpoint: a required model and prompt, along with optional sampling controls (temperature, top_p, frequency_penalty, presence_penalty), output controls (max_tokens, n, best_of, stop, suffix), reproducibility (seed), logging (logprobs, logit_bias, echo), and user identification. The streaming variants add a stream field and optional stream_options.

Usage

Import this type when constructing or type-hinting parameters for client.completions.create().

Code Reference

Source Location

Signature

class CompletionCreateParamsBase(TypedDict, total=False):
    model: Required[Union[str, Literal["gpt-3.5-turbo-instruct", "davinci-002", "babbage-002"]]]
    prompt: Required[Union[str, SequenceNotStr[str], Iterable[int], Iterable[Iterable[int]], None]]
    best_of: Optional[int]
    echo: Optional[bool]
    frequency_penalty: Optional[float]
    logit_bias: Optional[Dict[str, int]]
    logprobs: Optional[int]
    max_tokens: Optional[int]
    n: Optional[int]
    presence_penalty: Optional[float]
    seed: Optional[int]
    stop: Union[Optional[str], SequenceNotStr[str], None]
    stream_options: Optional[ChatCompletionStreamOptionsParam]
    suffix: Optional[str]
    temperature: Optional[float]
    top_p: Optional[float]
    user: str

class CompletionCreateParamsNonStreaming(CompletionCreateParamsBase, total=False):
    stream: Optional[Literal[False]]

class CompletionCreateParamsStreaming(CompletionCreateParamsBase):
    stream: Required[Literal[True]]

CompletionCreateParams = Union[CompletionCreateParamsNonStreaming, CompletionCreateParamsStreaming]

Import

from openai.types import CompletionCreateParams

I/O Contract

Fields (Base)

Name Type Required Description
model Union[str, Literal[...]] Yes Model ID (e.g. "gpt-3.5-turbo-instruct", "davinci-002", "babbage-002")
prompt Union[str, List[str], List[int], ...] Yes Prompt(s) as string, string array, token array, or nested token arrays
best_of Optional[int] No Generate N completions server-side, return the best one
echo Optional[bool] No Echo the prompt in addition to the completion
frequency_penalty Optional[float] No Penalty for token frequency (-2.0 to 2.0)
logit_bias Optional[Dict[str, int]] No Token ID to bias value mapping (-100 to 100)
logprobs Optional[int] No Return log probabilities for top N tokens (max 5)
max_tokens Optional[int] No Maximum tokens to generate
n Optional[int] No Number of completions to generate per prompt
presence_penalty Optional[float] No Penalty for token presence (-2.0 to 2.0)
seed Optional[int] No Seed for deterministic sampling
stop Union[str, List[str], None] No Up to 4 stop sequences
stream_options Optional[ChatCompletionStreamOptionsParam] No Streaming response options
suffix Optional[str] No Suffix after completion (gpt-3.5-turbo-instruct only)
temperature Optional[float] No Sampling temperature (0 to 2)
top_p Optional[float] No Nucleus sampling probability mass threshold
user str No End-user identifier for abuse monitoring

Usage Examples

from openai import OpenAI

client = OpenAI()

# Non-streaming completion
completion = client.completions.create(
    model="gpt-3.5-turbo-instruct",
    prompt="Write a haiku about programming:",
    max_tokens=50,
    temperature=0.7,
    n=1,
)

# Streaming completion
stream = client.completions.create(
    model="gpt-3.5-turbo-instruct",
    prompt="Once upon a time",
    max_tokens=100,
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].text, end="")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment