LLM providers

LLM modules to connect to different LLM providers. Also extracts code, name and description.

class iohblade.llm.Claude_LLM(api_key, model='claude-opus-5-5', base_url=None, max_tokens=16000, temperature=None, effort=None, fallbacks=None, **kwargs)

Bases: LLM

A manager class for handling requests to Anthropic’s Claude models.

get_config() → list[dict[str, Any]]

The configuration of the LLM(s), logged with every run.

Returns:

One dictionary per model (several for Multi_LLM) with the keys model (str), config (dict) and hardware (dict, empty unless the hardware is known).

Return type:

list[dict[str, Any]]

class iohblade.llm.DeepSeek_LLM(api_key, model='deepseek-chat', temperature=0.8, **kwargs)

Bases: OpenAI_LLM

A manager class for the DeepSeek chat models.

class iohblade.llm.Dummy_LLM(model='DUMMY', **kwargs)

Bases: LLM

get_config() → list[dict[str, Any]]

The configuration of the LLM(s), logged with every run.

Returns:

One dictionary per model (several for Multi_LLM) with the keys model (str), config (dict) and hardware (dict, empty unless the hardware is known).

Return type:

list[dict[str, Any]]

class iohblade.llm.Gemini_LLM(api_key, model='gemini-2.0-flash', generation_config=None, **kwargs)

Bases: LLM

A manager class for handling requests to Google’s Gemini models.

get_config() → list[dict[str, Any]]

The configuration of the LLM(s), logged with every run.

Returns:

One dictionary per model (several for Multi_LLM) with the keys model (str), config (dict) and hardware (dict, empty unless the hardware is known).

Return type:

list[dict[str, Any]]

class iohblade.llm.LLM(api_key, model='', base_url='', code_pattern=None, name_pattern=None, desc_pattern=None, cs_pattern=None, logger=None)

Bases: ABC

extract_algorithm_code(message)

Extracts algorithm code from a given message string using regular expressions.

Parameters:

message (str) – The message string containing the algorithm code.

Returns:

Extracted algorithm code.

Return type:

str

Raises:

NoCodeException – If no code block is found within the message.

extract_algorithm_description(message)

Extracts algorithm description from a given message string using regular expressions.

Parameters:

message (str) – The message string containing the algorithm name and code.

Returns:

Extracted algorithm name or empty string.

Return type:

str

extract_classname(code)

Extract the Python class name from a given code string (if possible).

Parameters:

code (string) – The code string to extract from.

Returns:

The Python class name or empty string.

Return type:

classname (string)

extract_configspace(message)

Extracts the configuration space definition in json from a given message string using regular expressions.

Parameters:

message (str) – The message string containing the algorithm code.

Returns:

Extracted configuration space object.

Return type:

ConfigSpace

abstractmethod get_config() → list[dict[str, Any]]

The configuration of the LLM(s), logged with every run.

Returns:

One dictionary per model (several for Multi_LLM) with the keys model (str), config (dict) and hardware (dict, empty unless the hardware is known).

Return type:

list[dict[str, Any]]

query(session: list, **kwargs)

Sends a conversation history to the configured model and returns the response text.

Parameters:
  • session_messages (list of dict) – A list of message dictionaries with keys “role” (e.g. “user”, “assistant”) and “content” (the message text).

  • **kwargs – Settings passed on to the provider’s _query (for example temperature), for providers that accept them.

Returns:

The text content of the LLM’s response.

Return type:

str

sample_solution(session_messages: list, parent_ids=[], HPO=False, base_code: str | None = None, diff_mode: bool = False, **kwargs)

Interacts with a language model to generate or mutate solutions based on the provided session messages.

Parameters:
  • session_messages (list) – A list of dictionaries with keys ‘role’ and ‘content’ to simulate a conversation with the language model.

  • parent_ids (list, optional) – The id of the parent the next sample will be generated from (if any).

  • HPO (boolean, optional) – If HPO is enabled, a configuration space will also be extracted (if possible).

  • base_code (str, optional) – Only accepted for compatibility with LLaMEA; not used.

  • diff_mode (bool, optional) – Only accepted for compatibility with LLaMEA; not supported (a warning is shown).

  • **kwargs – Additional LLM settings that can be used at query time.

Returns:

The new solution with its code, name, description and (with HPO) configuration space.

Return type:

Solution

Raises:
  • NoCodeException – If the language model fails to return any code.

  • Exception – Captures and logs any other exceptions that occur during the interaction.

set_logger(logger)

Sets the logger object to log the conversation.

Parameters:

logger (Logger) – A logger object to log the conversation.

to_dict()

Returns a dictionary representation of the LLM including all parameters.

Returns:

Dictionary representation of the LLM.

Return type:

dict

class iohblade.llm.LMStudio_LLM(model, config=None, **kwargs)

Bases: LLM

A manager for running MLX-Optimised LLM locally.

get_config() → list[dict[str, Any]]

The configuration of the LLM(s), logged with every run.

Returns:

One dictionary per model (several for Multi_LLM) with the keys model (str), config (dict) and hardware (dict, empty unless the hardware is known).

Return type:

list[dict[str, Any]]

class iohblade.llm.MLX_LM_LLM(model, config=None, max_tokens: int = 12000, **kwargs)

Bases: LLM

An mlx_lm implementation for running large LLMs locally.

get_config() → list[dict[str, Any]]

The configuration of the LLM(s), logged with every run.

Returns:

One dictionary per model (several for Multi_LLM) with the keys model (str), config (dict) and hardware (dict, empty unless the hardware is known).

Return type:

list[dict[str, Any]]

class iohblade.llm.Multi_LLM(llms: list[LLM])

Bases: LLM

get_config() → list[dict[str, Any]]

The configuration of the LLM(s), logged with every run.

Returns:

One dictionary per model (several for Multi_LLM) with the keys model (str), config (dict) and hardware (dict, empty unless the hardware is known).

Return type:

list[dict[str, Any]]

set_logger(logger)

Sets the logger object to log the conversation.

Parameters:

logger (Logger) – A logger object to log the conversation.

class iohblade.llm.Ollama_LLM(model='llama3.2', port=11434, **kwargs)

Bases: LLM

get_config() → list[dict[str, Any]]

The configuration of the LLM(s), logged with every run.

Returns:

One dictionary per model (several for Multi_LLM) with the keys model (str), config (dict) and hardware (dict, empty unless the hardware is known).

Return type:

list[dict[str, Any]]

class iohblade.llm.OpenAI_LLM(api_key=None, model='gpt-4-turbo', temperature=0.8, base_url: str | None = None, extra_body: dict[str, Any] | None = None, timeout: float | None = None, **kwargs)

Bases: LLM

A manager class for handling requests to OpenAI’s GPT models.

get_config() → list[dict[str, Any]]

The configuration of the LLM(s), logged with every run.

Returns:

One dictionary per model (several for Multi_LLM) with the keys model (str), config (dict) and hardware (dict, empty unless the hardware is known).

Return type:

list[dict[str, Any]]

iohblade.llm.get_hardware_info() → Dict

Token usage and cost

Token usage and cost bookkeeping for LLM calls.

Providers report the tokens of every call in their API response. BLADE records that usage (TokenUsage) and prices it with a small table of list prices (MODEL_PRICES). No extra API calls are made.

Prices are first-party list prices in USD per million tokens, for the standard tier and the shortest context tier. Batch, priority, fast-mode, regional and long-context surcharges are not modelled. Models that are not in the table (local models, Ollama, models released after PRICES_CHECKED) are logged with cost 0.

iohblade.llm_costs.MODEL_PRICES: dict[str, ModelPrice] = {'claude-fable-5': ModelPrice(input=10.0, output=50.0, cache_read=1.0, cache_write=12.5), 'claude-fable-5-1': ModelPrice(input=10.0, output=50.0, cache_read=1.0, cache_write=12.5), 'claude-fable-5-2': ModelPrice(input=8.0, output=40.0, cache_read=0.2, cache_write=10.0), 'claude-haiku-4-5': ModelPrice(input=1.0, output=5.0, cache_read=0.1, cache_write=1.25), 'claude-haiku-5-5': ModelPrice(input=0.1, output=0.5, cache_read=0.010000000000000002, cache_write=0.125), 'claude-opus-4-6': ModelPrice(input=5.0, output=25.0, cache_read=0.5, cache_write=6.25), 'claude-opus-4-7': ModelPrice(input=5.0, output=25.0, cache_read=0.5, cache_write=6.25), 'claude-opus-4-8': ModelPrice(input=5.0, output=25.0, cache_read=0.5, cache_write=6.25), 'claude-opus-5': ModelPrice(input=5.0, output=25.0, cache_read=0.5, cache_write=6.25), 'claude-opus-5-5': ModelPrice(input=4.0, output=20.0, cache_read=0.2, cache_write=5.0), 'claude-sonnet-4-5': ModelPrice(input=3.0, output=15.0, cache_read=0.30000000000000004, cache_write=3.75), 'claude-sonnet-4-6': ModelPrice(input=3.0, output=15.0, cache_read=0.30000000000000004, cache_write=3.75), 'claude-sonnet-5': ModelPrice(input=2.0, output=10.0, cache_read=0.2, cache_write=2.5), 'claude-sonnet-5-5': ModelPrice(input=2.0, output=10.0, cache_read=0.1, cache_write=2.5), 'deepseek-flash': ModelPrice(input=0.3, output=1.2, cache_read=0.006, cache_write=None), 'deepseek-v4-pro': ModelPrice(input=1.32, output=3.96, cache_read=0.044, cache_write=None), 'gemini-2.5-flash': ModelPrice(input=0.3, output=2.5, cache_read=0.03, cache_write=None), 'gemini-2.5-flash-lite': ModelPrice(input=0.1, output=0.4, cache_read=0.01, cache_write=None), 'gemini-2.5-pro': ModelPrice(input=1.25, output=10.0, cache_read=0.125, cache_write=None), 'gemini-3-flash-preview': ModelPrice(input=0.5, output=3.0, cache_read=0.05, cache_write=None), 'gemini-3.1-flash-lite': ModelPrice(input=0.25, output=1.5, cache_read=0.025, cache_write=None), 'gemini-3.1-pro-preview': ModelPrice(input=2.0, output=12.0, cache_read=0.2, cache_write=None), 'gemini-3.5-flash-lite': ModelPrice(input=0.3, output=2.5, cache_read=0.03, cache_write=None), 'gemini-3.6-flash': ModelPrice(input=0.75, output=3.75, cache_read=0.075, cache_write=None), 'gemini-3.8-flash': ModelPrice(input=0.75, output=3.75, cache_read=0.075, cache_write=None), 'gemini-4-argon': ModelPrice(input=2.0, output=10.0, cache_read=0.1, cache_write=None), 'gemini-4-carbon': ModelPrice(input=2.0, output=10.0, cache_read=0.1, cache_write=None), 'gemini-4-hydrogen': ModelPrice(input=1.5, output=7.5, cache_read=0.075, cache_write=None), 'gemini-4-neon': ModelPrice(input=3.0, output=15.0, cache_read=0.15, cache_write=None), 'gpt-4.1': ModelPrice(input=2.0, output=8.0, cache_read=0.5, cache_write=None), 'gpt-4.1-mini': ModelPrice(input=0.4, output=1.6, cache_read=0.1, cache_write=None), 'gpt-4o': ModelPrice(input=2.5, output=10.0, cache_read=1.25, cache_write=None), 'gpt-4o-mini': ModelPrice(input=0.15, output=0.6, cache_read=0.075, cache_write=None), 'gpt-5': ModelPrice(input=1.25, output=10.0, cache_read=0.125, cache_write=None), 'gpt-5-mini': ModelPrice(input=0.25, output=2.0, cache_read=0.025, cache_write=None), 'gpt-5-nano': ModelPrice(input=0.05, output=0.4, cache_read=0.005, cache_write=None), 'gpt-5-pro': ModelPrice(input=15.0, output=120.0, cache_read=None, cache_write=None), 'gpt-5.1': ModelPrice(input=1.25, output=10.0, cache_read=0.125, cache_write=None), 'gpt-5.2': ModelPrice(input=1.75, output=14.0, cache_read=0.175, cache_write=None), 'gpt-5.2-pro': ModelPrice(input=21.0, output=168.0, cache_read=None, cache_write=None), 'gpt-5.4': ModelPrice(input=2.5, output=15.0, cache_read=0.25, cache_write=None), 'gpt-5.4-mini': ModelPrice(input=0.75, output=4.5, cache_read=0.075, cache_write=None), 'gpt-5.4-nano': ModelPrice(input=0.2, output=1.25, cache_read=0.02, cache_write=None), 'gpt-5.4-pro': ModelPrice(input=30.0, output=180.0, cache_read=None, cache_write=None), 'gpt-5.5': ModelPrice(input=5.0, output=30.0, cache_read=0.5, cache_write=None), 'gpt-5.5-pro': ModelPrice(input=30.0, output=180.0, cache_read=None, cache_write=None), 'gpt-5.6-luna': ModelPrice(input=0.2, output=1.2, cache_read=0.02, cache_write=None), 'gpt-5.6-sol': ModelPrice(input=4.0, output=20.0, cache_read=0.4, cache_write=None), 'gpt-5.6-terra': ModelPrice(input=2.0, output=12.0, cache_read=0.2, cache_write=None), 'gpt-6-astra': ModelPrice(input=10.0, output=50.0, cache_read=1.0, cache_write=None), 'gpt-6-luna': ModelPrice(input=0.1, output=0.5, cache_read=0.01, cache_write=None), 'gpt-6-sol': ModelPrice(input=2.0, output=10.0, cache_read=0.2, cache_write=None), 'gpt-6.1-sol': ModelPrice(input=2.0, output=10.0, cache_read=0.1, cache_write=None), 'gpt-6.1-terra': ModelPrice(input=1.0, output=5.0, cache_read=0.05, cache_write=None), 'gpt-6.2-astra': ModelPrice(input=8.0, output=40.0, cache_read=0.4, cache_write=None), 'gpt-6.2-sol': ModelPrice(input=2.0, output=10.0, cache_read=0.1, cache_write=None), 'o3': ModelPrice(input=2.0, output=8.0, cache_read=0.5, cache_write=None), 'o3-pro': ModelPrice(input=20.0, output=80.0, cache_read=None, cache_write=None)}

USD per million tokens, checked on PRICES_CHECKED.

class iohblade.llm_costs.ModelPrice(input: float, output: float, cache_read: float | None = None, cache_write: float | None = None)

Bases: object

List price of a model in USD per million tokens.

Parameters:
  • input – Uncached input (prompt) tokens.

  • output – Output tokens, thinking/reasoning tokens included.

  • cache_read – Input tokens read from the prompt cache. None uses the input price.

  • cache_write – Input tokens written to the prompt cache (Anthropic). None uses the input price.

iohblade.llm_costs.PRICES_CHECKED = '2026-11-26'

Date on which the prices below were checked against the providers’ pricing pages.

class iohblade.llm_costs.TokenUsage(input_tokens: int = 0, output_tokens: int = 0, cache_read_tokens: int = 0, cache_write_tokens: int = 0, model: str | None = None)

Bases: object

Tokens of one LLM call, as reported by the provider.

Parameters:
  • input_tokens – Uncached input tokens (billed at the input price).

  • output_tokens – Output tokens, thinking/reasoning tokens included when the provider reports them.

  • cache_read_tokens – Input tokens served from the prompt cache.

  • cache_write_tokens – Input tokens written to the prompt cache.

  • model – The model that answered, if the provider says so.

completion_cost(model: str | None = None) → float

USD cost of the output tokens (0 for an unpriced model).

prompt_cost(model: str | None = None) → float

USD cost of the input tokens (0 for an unpriced model).

property prompt_tokens: int

All input tokens, cached or not.

iohblade.llm_costs.anthropic_usage(response) → TokenUsage | None

Usage of a Claude Messages API response.

input_tokens excludes cached tokens; output_tokens includes thinking tokens.

iohblade.llm_costs.estimate_tokens(text: str | None) → int

A rough token count of text (about four characters per token).

Used only when a provider reports no usage, for example in custom LLM classes.

iohblade.llm_costs.gemini_usage(response) → TokenUsage | None

Usage of a google-genai response.

candidates_token_count excludes thinking, so thoughts_token_count is added to the output tokens.

iohblade.llm_costs.model_price(model: str | None) → ModelPrice | None

The list price of model, or None if it is not in the table.

Dated snapshots (gpt-4o-2024-08-06, claude-opus-4-5@20251101) and platform prefixes (models/, anthropic.) are recognised.

iohblade.llm_costs.ollama_usage(response) → TokenUsage | None

Usage of an Ollama chat response (prompt_eval_count/eval_count).

iohblade.llm_costs.openai_usage(response) → TokenUsage | None

Usage of an OpenAI-compatible chat completion (OpenAI, DeepSeek, vLLM).

prompt_tokens includes cached tokens and completion_tokens includes reasoning tokens.