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 Model

From Leeroopedia
Revision as of 13:37, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Openai_Openai_python_Completion_Model.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains API_Types, Python
Last Updated 2026-02-15 00:00 GMT

Overview

Concrete type for the legacy Completion response object provided by the openai-python SDK.

Description

The Completion Pydantic model represents a response from the legacy completions API endpoint (/v1/completions). It contains an id, a list of choices (each a CompletionChoice), a created timestamp, the model used, an object type fixed to "text_completion", an optional system_fingerprint for tracking backend configuration, and optional usage statistics. Note that both streamed and non-streamed responses share the same shape, unlike the chat endpoint.

Usage

Import this type when working with the legacy completions endpoint via client.completions.create(). For modern chat-based completions, use the chat completion types instead.

Code Reference

Source Location

Signature

class Completion(BaseModel):
    id: str
    choices: List[CompletionChoice]
    created: int
    model: str
    object: Literal["text_completion"]
    system_fingerprint: Optional[str] = None
    usage: Optional[CompletionUsage] = None

Import

from openai.types import Completion

I/O Contract

Fields

Name Type Required Description
id str Yes Unique identifier for the completion
choices List[CompletionChoice] Yes List of completion choices generated for the input prompt
created int Yes Unix timestamp (seconds) when the completion was created
model str Yes The model used for completion
object Literal["text_completion"] Yes Object type, always "text_completion"
system_fingerprint Optional[str] No Backend configuration fingerprint for determinism tracking
usage Optional[CompletionUsage] No Token usage statistics for the request

Usage Examples

from openai import OpenAI

client = OpenAI()

completion = client.completions.create(
    model="gpt-3.5-turbo-instruct",
    prompt="Say hello in French:",
    max_tokens=50,
)
print(completion.id)
print(completion.choices[0].text)
if completion.usage:
    print(f"Tokens used: {completion.usage.total_tokens}")

Related Pages

Page Connections

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