Principle:Openai Openai node Request Construction
| 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:
- Define the conversation messages (required)
- Select the model (required)
- Set optional generation parameters (temperature, max_tokens)
- Configure streaming mode if needed
- Add tool definitions for function calling
- 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>.