Skip to main content

OpenAIAPIClient

OpenAIAPIClient is the OpenAI-compatible HTTP client in AutoPipeline. It is implemented in src/autopipeline/components/primitives/clients/openai_client.py and registered in CLIENT_REGISTRY as api.

Client
Overview

Registry Entry

FieldValue
Registry keyapi
ClassOpenAIAPIClient
Base classBaseClient
Signature

Class Signature

OpenAIAPIClient(
model_name: str = "gpt-4o",
**kwargs,
)
Constructor

Constructor Parameters

KeyRequiredDefaultMeaning
model_nameNogpt-4oModel name sent in the OpenAI-style request body.
base_urlYesnoneFull chat-completions endpoint URL.
api_keyYesnoneBearer token used in the Authorization header.
max_tokensNo2048Maximum generated tokens.
retriesNo3Retry budget after request failures.
timeoutNo600Request timeout in seconds.

The constructor asserts that base_url and api_key are present.

Methods

Public Methods

MethodPurpose
call_model(messages)Execute one OpenAI-style chat-completions HTTP request with retries.
Signature

Callable Interface

call_model(messages) -> str | None

Input contract

messages must already be an OpenAI-style chat payload, typically produced by OpenAIStylePromptAdapter.

Request body

The client sends:

{
"model": "<model_name>",
"stream": false,
"max_tokens": 2048,
"messages": [...]
}

Return value

On success, the method returns:

resp.json()["choices"][0]["message"]["content"].strip()

On terminal failure, it returns None.

Config

Minimal Config Example

init_config:
backend: api
model_name: gpt-4o
base_url: ${client_config.base_url}
api_key: ${client_config.api_key}
max_tokens: 2048
retries: 3
timeout: 600
Failure Mode

Failure Semantics

The method retries on any exception:

  • sleeps for two seconds between attempts
  • increments an internal retry counter
  • returns None after the retry budget is exhausted

Because the retry loop catches broad exceptions, caller code should treat None as the canonical transport failure signal.

Extension

Extension Notes

  • Reuse this client when your backend already speaks the OpenAI chat-completions protocol.
  • Replace it only if the wire format or response extraction logic changes materially.
  • Keep prompt formatting in prompt_adapters.py, not here.