ClaudeInference#

class rapidtools.models.ClaudeInference(api_key: str | Path | None = None, model_id: str = 'claude-opus-5', 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)[source]#

Bases: BaseAPIInferenceModel

Anthropic Claude Messages API client for image + text prompts.

The key is read from api_key (string or key-file path) or the ANTHROPIC_API_KEY environment variable. Thinking blocks returned by current models are skipped; only text blocks are concatenated into ModelOutput.text. A refusal stop reason yields None.

Example

>>> from rapidtools.models import ClaudeInference
>>> ClaudeInference.list_known_models()[:3]
['claude-fable-5-1', 'claude-fable-5', 'claude-opus-5']
>>> model = ClaudeInference(api_key='sk-ant-...')
>>> out = model.run_inference(
...     ['front.jpg', 'back.jpg'],
...     'Return JSON with keys damage_level and justification.',
...     json_mode=True,
... )
>>> out.text
'{"damage_level": 2, "justification": "minor roof damage"}'

Methods

list_available_models

List the Claude 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 the Messages API.

supports_temperature

Return whether model_id accepts the temperature parameter.

classmethod list_available_models(api_key: str | Path | None = None) → list[str][source]#

List the Claude model IDs accessible with api_key.

Without a key (or when the API cannot be reached) the curated catalogue is returned instead.

Parameters:

api_key – Key string, key-file path, or None for the env var.

Returns:

list[str] – Sorted model IDs.

Example

>>> from rapidtools.models import ClaudeInference
>>> ids = ClaudeInference.list_available_models('sk-ant-...')
>>> 'claude-opus-5' in ids
True
static supports_temperature(model_id: str) → bool[source]#

Return whether model_id accepts the temperature parameter.

Example

>>> from rapidtools.models import ClaudeInference
>>> ClaudeInference.supports_temperature('claude-opus-5')
False
>>> ClaudeInference.supports_temperature('claude-haiku-4-5')
True
run_inference(image_inputs: str | Path | list[str | Path], prompt: str | Path, json_mode: bool = False, max_retries: int | None = None, temperature: float | None = None, max_tokens: int | None = None, config: GenerationConfig | None = None, **kwargs: Any) → ModelOutput | None[source]#

Send images and a prompt to the Messages API.

Parameters:
  • image_inputs – One path/URL or a list of them. Unreadable images are skipped with a logged error.

  • prompt – Prompt text or path to a prompt file.

  • json_mode – Add a system instruction demanding JSON-only output.

  • max_retries – Per-call override of the session retry count.

  • temperature – Per-call temperature override (ignored by models that do not accept it).

  • max_tokens – Per-call output-token limit override.

  • config – A GenerationConfig; explicit keyword arguments take precedence over it.

  • **kwargs – Ignored; accepted for interface compatibility.

Returns:

ModelOutput | None – The response text and raw JSON, or None when the request failed, was refused, or nothing could be sent.

Example

>>> from rapidtools.models import ClaudeInference
>>> model = ClaudeInference(api_key='sk-ant-...')
>>> model.run_inference('house.jpg', 'Is the house standing?').text
'Yes, the house is standing with visible roof damage.'