Skip to content
Open
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
3 changes: 2 additions & 1 deletion scrapegraphai/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This module contains the model definitions used in the ScrapeGraphAI application.
"""

from .apiroute import APIRoute
from .atlascloud import AtlasCloud
from .cheaperinference import CheaperInference
from .clod import CLoD
Expand All @@ -13,4 +14,4 @@
from .openai_tts import OpenAITextToSpeech
from .xai import XAI

__all__ = ["AtlasCloud", "CheaperInference", "DeepSeek", "MiniMax", "OneApi", "OpenAIImageToText", "OpenAITextToSpeech", "CLoD", "XAI", "Nvidia"]
__all__ = ["APIRoute", "AtlasCloud", "CheaperInference", "DeepSeek", "MiniMax", "OneApi", "OpenAIImageToText", "OpenAITextToSpeech", "CLoD", "XAI", "Nvidia"]
14 changes: 14 additions & 0 deletions scrapegraphai/models/apiroute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""API Route OpenAI-compatible chat model wrapper."""

from langchain_openai import ChatOpenAI


class APIRoute(ChatOpenAI):
"""Use API Route models through its fixed OpenAI-compatible endpoint."""

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://global.api-route.com/v1"

super().__init__(**llm_config)
19 changes: 19 additions & 0 deletions tests/test_apiroute_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Tests for the API Route model wrapper."""

import importlib.util
from pathlib import Path


def test_apiroute_uses_fixed_endpoint_and_api_key():
"""The wrapper should configure ChatOpenAI without making a network call."""
model_path = (
Path(__file__).resolve().parents[1] / "scrapegraphai/models/apiroute.py"
)
spec = importlib.util.spec_from_file_location("apiroute", model_path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)

model = module.APIRoute(api_key="test-key", model="gpt-5.5")

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