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
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
Basic example of scraping pipeline using SmartScraper with TeamoRouter
"""

import json
import os

from dotenv import load_dotenv

from scrapegraphai.graphs import SmartScraperGraph
from scrapegraphai.utils import prettify_exec_info

load_dotenv()

# ************************************************
# Define the configuration for the graph
# ************************************************

graph_config = {
"llm": {
"api_key": os.getenv("TEAMOROUTER_API_KEY"),
# Any chat model id from https://api.teamorouter.com/v1/models,
# prefixed with "teamorouter/".
"model": "teamorouter/deepseek-v4-flash",
},
"verbose": True,
"headless": True,
}

# ************************************************
# Create the SmartScraperGraph instance and run it
# ************************************************

smart_scraper_graph = SmartScraperGraph(
prompt="List the first 5 books with their title and price",
source="https://books.toscrape.com/",
config=graph_config,
)

result = smart_scraper_graph.run()
print(json.dumps(result, indent=4))

# ************************************************
# Get graph execution info
# ************************************************

graph_exec_info = smart_scraper_graph.get_execution_info()
print(prettify_exec_info(graph_exec_info))
7 changes: 6 additions & 1 deletion scrapegraphai/graphs/abstract_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from pydantic import BaseModel

from ..helpers import models_tokens
from ..models import XAI, CLoD, DeepSeek, MiniMax, Nvidia, OneApi
from ..models import XAI, CLoD, DeepSeek, MiniMax, Nvidia, OneApi, TeamoRouter
from ..utils.logging import get_logger, set_verbosity_info, set_verbosity_warning

logger = get_logger(__name__)
Expand Down Expand Up @@ -172,6 +172,7 @@ def _create_llm(self, llm_config: dict) -> object:
"ernie",
"fireworks",
"clod",
"teamorouter",
"togetherai",
"xai",
"minimax",
Expand Down Expand Up @@ -241,6 +242,7 @@ def _create_llm(self, llm_config: dict) -> object:
"deepseek",
"togetherai",
"clod",
"teamorouter",
"xai",
"minimax",
}:
Expand All @@ -257,6 +259,9 @@ def _create_llm(self, llm_config: dict) -> object:
if model_provider == "clod":
return CLoD(**llm_params)

if model_provider == "teamorouter":
return TeamoRouter(**llm_params)

if model_provider == "deepseek":
return DeepSeek(**llm_params)

Expand Down
8 changes: 8 additions & 0 deletions scrapegraphai/helpers/models_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,14 @@
"gpt-5.4-mini": 400000,
"gpt-5.4": 1000000,
},
"teamorouter": {
"deepseek-v4-flash": 1000000,
"deepseek-v4-pro": 1000000,
"qwen3.8-flash": 1000000,
"qwen3.8-max": 1000000,
"kimi-k3": 1000000,
"glm-5.3": 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 @@ -11,6 +11,7 @@
from .oneapi import OneApi
from .openai_itt import OpenAIImageToText
from .openai_tts import OpenAITextToSpeech
from .teamorouter import TeamoRouter
from .xai import XAI

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

from langchain_openai import ChatOpenAI

TEAMOROUTER_API_BASE = "https://api.teamorouter.com/v1"
TEAMOROUTER_CLIENT_SOURCE = "scrapegraphai-teamorouter"


class TeamoRouter(ChatOpenAI):
"""
A wrapper for ChatOpenAI configured for TeamoRouter's OpenAI-compatible
API (https://teamorouter.com), which serves DeepSeek, Qwen, Kimi, GLM and
other models behind one API key.

Requests carry an ``X-Client-Source`` header so TeamoRouter can attribute
traffic to ScrapeGraphAI; headers passed in ``default_headers`` take
precedence.

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"] = TEAMOROUTER_API_BASE
llm_config["default_headers"] = {
"X-Client-Source": TEAMOROUTER_CLIENT_SOURCE,
**(llm_config.get("default_headers") or {}),
}

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

import importlib.util
import os


def _load(name, *parts):
spec = importlib.util.spec_from_file_location(
name, os.path.join(os.path.dirname(__file__), "..", "scrapegraphai", *parts)
)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module


def test_teamorouter_model_sets_openai_compatible_base_url():
"""TeamoRouter should map api_key, set its base URL and tag requests."""
module = _load("teamorouter", "models", "teamorouter.py")

model = module.TeamoRouter(api_key="test-key", model="deepseek-v4-flash")

assert str(model.openai_api_base).rstrip("/") == "https://api.teamorouter.com/v1"
assert model.openai_api_key.get_secret_value() == "test-key"
assert model.default_headers["X-Client-Source"] == "scrapegraphai-teamorouter"


def test_teamorouter_model_keeps_user_headers():
"""Headers passed by the caller are kept and can override the default tag."""
module = _load("teamorouter", "models", "teamorouter.py")

model = module.TeamoRouter(
api_key="test-key",
model="deepseek-v4-flash",
default_headers={"X-Client-Source": "my-app", "X-Trace": "1"},
)

assert model.default_headers["X-Client-Source"] == "my-app"
assert model.default_headers["X-Trace"] == "1"


def test_teamorouter_models_in_token_list():
"""TeamoRouter defaults should be listed with their context lengths."""
module = _load("models_tokens", "helpers", "models_tokens.py")

teamorouter_models = module.models_tokens["teamorouter"]
assert teamorouter_models["deepseek-v4-flash"] == 1000000
assert teamorouter_models["qwen3.8-flash"] == 1000000