Skip to content

ccproxy.llms.models.openai

ccproxy.llms.models.openai

Pydantic V2 models for OpenAI API endpoints based on the provided reference.

This module contains data structures for: - /v1/chat/completions (including streaming) - /v1/embeddings - /v1/models - /v1/responses (including streaming) - Common Error structures

The models are defined using modern Python 3.11 type hints and Pydantic V2 best practices.

ErrorDetail

Bases: LlmBaseModel

Detailed information about an API error.

ErrorResponse

Bases: LlmBaseModel

The structure of an error response from the OpenAI API.

Model

Bases: LlmBaseModel

Represents a model available in the API.

ModelList

Bases: LlmBaseModel

A list of available models.

EmbeddingRequest

Bases: LlmBaseModel

Request body for creating an embedding.

EmbeddingData

Bases: LlmBaseModel

Represents a single embedding vector.

EmbeddingUsage

Bases: LlmBaseModel

Token usage statistics for an embedding request.

EmbeddingResponse

Bases: LlmBaseModel

Response object for an embedding request.

ResponseFormat

Bases: LlmBaseModel

An object specifying the format that the model must output.

FunctionDefinition

Bases: LlmBaseModel

The definition of a function that the model can call.

Tool

Bases: LlmBaseModel

A tool the model may call.

ChatMessage

Bases: LlmBaseModel

A message within a chat conversation.

ChatCompletionRequest

Bases: LlmBaseModel

Request body for creating a chat completion.

OutputItem

Bases: LlmBaseModel

Normalized representation of a Responses API output item.

OpenAI currently emits different shapes for text, tool, and reasoning items. Some omit fields like status or role entirely, while others include extra metadata such as summary or call_id. Keeping these attributes optional lets us validate real-world payloads without fighting the schema.

generate_responses_id

generate_responses_id()

Generate an OpenAI-compatible response ID.

Source code in ccproxy/llms/models/openai.py
def generate_responses_id() -> str:
    """Generate an OpenAI-compatible response ID."""
    return f"chatcmpl-{uuid.uuid4().hex[:29]}"