OpenAIInference

Contents

OpenAIInference#

class rapidtools.models.OpenAIInference(api_key: str | Path | None = None, model_id: str | None = None, max_workers: int = 10, max_retries: int = 3, system_instruction: str | None = None, temperature: float = 0.4, max_tokens: int = 2048, timeout: float = 60.0, base_url: str | None = None)[source]#

Bases: BaseOpenAICompatibleInference

OpenAI Chat Completions client for image + text prompts.

The key is read from api_key (string or key-file path) or the OPENAI_API_KEY environment variable. Reasoning models (GPT-5.x, GPT-6, o-series) do not accept temperature; it is omitted automatically.

Example

>>> from rapidtools.models import OpenAIInference
>>> OpenAIInference.list_known_models()[:2]
['gpt-6-astra', 'gpt-6-sol']
>>> model = OpenAIInference(api_key='sk-...')
>>> for asset_id, status, out in model.run_batch(
...     [('b1', ['b1.jpg']), ('b2', ['b2.jpg'])], 'Rate the damage 0-5.'
... ):
...     print(asset_id, status, out.text if status == 'ok' else out)

Methods

list_available_models

List the model IDs accessible with api_key.

list_known_models

Return the curated catalogue of model IDs for this provider.

run_batch

Run run_inference() over many assets with a thread pool.

run_inference

Send images and a prompt to /chat/completions.