Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions scrapegraphai/helpers/models_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@
"deepseek-ai/deepseek-v4-pro": 1048576,
"qwen/qwen3.5-flash": 1000000,
},
"cheaperinference": {
"gpt-5.4-mini": 400000,
"gpt-5.4": 1000000,
},
"deepseek": {
"deepseek-chat": 128000,
"deepseek-coder": 128000,
Expand Down
3 changes: 2 additions & 1 deletion scrapegraphai/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from .atlascloud import AtlasCloud
from .cheaperinference import CheaperInference
from .clod import CLoD
from .deepseek import DeepSeek
from .minimax import MiniMax
Expand All @@ -12,4 +13,4 @@
from .openai_tts import OpenAITextToSpeech
from .xai import XAI

__all__ = ["AtlasCloud", "DeepSeek", "MiniMax", "OneApi", "OpenAIImageToText", "OpenAITextToSpeech", "CLoD", "XAI", "Nvidia"]
__all__ = ["AtlasCloud", "CheaperInference", "DeepSeek", "MiniMax", "OneApi", "OpenAIImageToText", "OpenAITextToSpeech", "CLoD", "XAI", "Nvidia"]
22 changes: 22 additions & 0 deletions scrapegraphai/models/cheaperinference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Cheaper Inference Module
"""

from langchain_openai import ChatOpenAI


class CheaperInference(ChatOpenAI):
"""
A wrapper for ChatOpenAI configured for Cheaper Inference's OpenAI-compatible
LLM API. Each model costs 15–60% less than the list price of its lab.

Args:
llm_config (dict): Configuration parameters for the language model.
"""

def __init__(self, **llm_config):
if "api_key" in llm_config:
llm_config["openai_api_key"] = llm_config.pop("api_key")
llm_config["openai_api_base"] = "https://api.cheaperinference.com/v1"

super().__init__(**llm_config)
50 changes: 50 additions & 0 deletions tests/test_cheaperinference_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""Tests for Cheaper Inference model configuration."""

import importlib.util
import os


def test_cheaperinference_model_sets_openai_compatible_base_url():
"""CheaperInference should map api_key and set its base URL."""
spec = importlib.util.spec_from_file_location(
"cheaperinference",
os.path.join(
os.path.dirname(__file__),
"..",
"scrapegraphai",
"models",
"cheaperinference.py",
),
)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)

model = module.CheaperInference(
api_key="test-key",
model="gpt-5.4-mini",
)

assert (
str(model.openai_api_base).rstrip("/") == "https://api.cheaperinference.com/v1"
)
assert model.openai_api_key.get_secret_value() == "test-key"


def test_cheaperinference_models_in_token_list():
"""Cheaper Inference defaults should be listed with current context lengths."""
spec = importlib.util.spec_from_file_location(
"models_tokens",
os.path.join(
os.path.dirname(__file__),
"..",
"scrapegraphai",
"helpers",
"models_tokens.py",
),
)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)

cheaperinference_models = module.models_tokens["cheaperinference"]
assert cheaperinference_models["gpt-5.4-mini"] == 400000
assert cheaperinference_models["gpt-5.4"] == 1000000