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
Constructor
Constructor Parameters
| Key | Required | Default | Meaning |
|---|---|---|---|
model_name | No | gpt-4o | Model name sent in the OpenAI-style request body. |
base_url | Yes | none | Full chat-completions endpoint URL. |
api_key | Yes | none | Bearer token used in the Authorization header. |
max_tokens | No | 2048 | Maximum generated tokens. |
retries | No | 3 | Retry budget after request failures. |
timeout | No | 600 | Request timeout in seconds. |
The constructor asserts that base_url and api_key are present.
Methods
Public Methods
| Method | Purpose |
|---|---|
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
Noneafter 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.