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.

Principle:Openai Openai node Request Construction

From Leeroopedia
Knowledge Sources
Domains NLP, API_Design
Last Updated 2026-02-15 00:00 GMT

Overview

A principle governing the assembly of a typed request object that specifies model selection, conversation context, and generation parameters for a language model API call.

Description

Request Construction involves building a structured parameter object that fully describes the desired API call. For chat completions, this includes the conversation messages array (system, user, assistant roles), the target model, and optional parameters controlling generation behavior (temperature, max tokens, streaming mode, tool definitions, response format).

The typed parameter interface serves as a contract between the caller and the API. By using TypeScript interfaces, the SDK provides compile-time validation of request shapes, preventing common errors like missing required fields or mistyped parameters.

Usage

Use this principle whenever preparing to call the Chat Completions or Responses API. The request object is the input to completions.create(), completions.stream(), or completions.parse().

Theoretical Basis

Request construction follows the Builder Pattern where a complex object is assembled step by step:

  1. Define the conversation messages (required)
  2. Select the model (required)
  3. Set optional generation parameters (temperature, max_tokens)
  4. Configure streaming mode if needed
  5. Add tool definitions for function calling
  6. Specify response format for structured outputs

Key design principle: The request type is a discriminated union — when stream: true is set, the return type changes from ChatCompletion to Stream<ChatCompletionChunk>.

Related Pages

Implemented By

Page Connections

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