10% off ALL new Proxies – CODE: 10pro

smolagents Proxy Setup: Route Agents via German Mobile IPs

smolagents Proxy Setup: Route Agents via German Mobile IPs

Direct Answer

To route smolagents through a mobile proxy, set HTTP_PROXY and HTTPS_PROXY on the process that runs the agent. smolagents is Hugging Face's lightweight agent framework, and its built-in web tool — VisitWebpageTool — fetches pages with Python's requests, which reads those variables automatically. So your German mobile IP is what fetches the pages. The model call keeps its own connection unless you route it through the proxy on purpose. You don't touch how the agent reasons or which tool it picks; you only change where the agent's web requests come from.


The One Thing Most smolagents Proxy Guides Get Wrong

smolagents lets a model write and run code (or call structured tools) to reach a goal: give it a task, add web tools, and it fetches, reads and reasons in a loop. The common mistake is thinking of "the proxy" as something the whole agent or the model sits behind. It isn't.

The proxy binds to the web tool, not the model. When the agent calls VisitWebpageTool to read a German page, that request is what should leave through your German mobile IP. The reasoning steps — the calls to your model — are a separate connection and usually don't need a German exit at all. Get this distinction right and the setup is a two-line change; get it wrong and you route model traffic through a mobile connection for no reason while your fetch still exits from your own address.

So the goal is precise: send the agent's outbound page fetches through the German mobile proxy, and leave everything else alone.


Before You Start

You'll need four values from your GermanProxy.io account:

  • Host and port of your endpoint
  • Username and password

The examples use PROXY_HOST, PORT, USER and PASS as placeholders — replace them with your own. There's no hardware to manage: the proxy is a dedicated mobile connection exposed as a host/port/credentials endpoint.

Install smolagents with its toolkit:

pip install "smolagents[toolkit]"

Step 1 — Set the Proxy on the Agent's Environment

smolagents' built-in VisitWebpageTool fetches pages with Python's requests, and requests honours HTTP_PROXY / HTTPS_PROXY automatically. Set them before you build the agent:

import os

PROXY = "http://USER:PASS@PROXY_HOST:PORT"
os.environ["HTTP_PROXY"] = PROXY
os.environ["HTTPS_PROXY"] = PROXY

That's the whole binding. Every tool built on requests now exits through your German mobile IP — no per-tool configuration needed for the common case.


Step 2 — Give the Agent a Web Tool and Run It

Here's a runnable agent that reads a German page through the proxy. The VisitWebpageTool is the piece that carries the German mobile IP:

import os
from smolagents import CodeAgent, VisitWebpageTool, InferenceClientModel

PROXY = "http://USER:PASS@PROXY_HOST:PORT"
os.environ["HTTP_PROXY"] = PROXY
os.environ["HTTPS_PROXY"] = PROXY

# This tool's requests exit through the German mobile IP.
agent = CodeAgent(
    tools=[VisitWebpageTool()],
    model=InferenceClientModel(),
)

result = agent.run(
    "Open https://www.example.de and report the page title and key public details."
)
print(result)

The model decides when to visit the page; the tool decides how the request leaves — and with the env vars set, it leaves through your German mobile IP.


Step 3 — Custom Tool With an Explicit Proxy Client

If you write your own smolagents tool, or want the German exit on one tool only, pass the proxy straight to that tool's HTTP client instead of relying on the environment:

import requests
from smolagents import tool

PROXY = "http://USER:PASS@PROXY_HOST:PORT"

@tool
def german_fetch(url: str) -> str:
    """Fetch a URL through the German mobile proxy.

    Args:
        url: The page to fetch.
    """
    proxies = {"http": PROXY, "https": PROXY}
    resp = requests.get(url, proxies=proxies, timeout=30)
    resp.raise_for_status()
    return resp.text

This is the right choice when one agent mixes a German-exit fetch tool with, say, a direct call to your own internal API — only the tool you configure carries the mobile IP.


Verify the IP First

Before a real run, confirm the exit IP is a German mobile address. The quickest check is a one-line request through the same proxy:

curl -x "http://USER:PASS@PROXY_HOST:PORT" https://api.ipify.org?format=json

If it returns your own address, the env vars didn't reach the agent's process or the custom client isn't using the proxy — re-check the URL and that the credentials are in it. Confirm the ASN and geolocation look like a German mobile network, not a datacenter range. A full checklist is in checking your proxy configuration.


Sticky Sessions vs. Rotation

How the agent should handle IPs depends on the task:

  • Sticky session — keep the same German mobile IP across a multi-step flow (open a page, follow links, extract) so a sequence of tool calls looks like one coherent visitor.
  • Rotation on demand — request a fresh IP at the proxy between runs to spread load across a longer job.

Keep request rates human-reasonable and cap how many tools fire at once. The mechanics are in sticky sessions and IP rotation.


Why a Mobile IP at All

German content is localised. German marketplaces and Google.de serve different results, pricing and stock by country and network. Have your agent fetch a German site from a US datacenter range and it measures the wrong market. A German IP gives it the in-country view the task needs.

Mobile IPs carry high IP reputation. German sites filter datacenter ranges aggressively — often a 403 Forbidden within a handful of requests. Mobile IPs sit in shared CGNAT pools used by thousands of real subscribers, so they carry high IP reputation — the reason a mobile IP keeps working where a datacenter range stalls.

For the trade-offs between IP types, see mobile vs residential vs datacenter proxy and, on cost, dedicated mobile vs pay-per-GB residential. For the wider agent picture, see mobile proxies for AI agents.


Scrape Responsibly

A mobile proxy improves reliability for legitimate data collection — it is not a tool to circumvent access controls or platform rules. An agent runs largely unattended, so the responsibility to keep it clean is higher, not lower:

  1. Respect robots.txt and each site's terms — bake the check into the tool, not just into intentions.
  2. Throttle — add a delay between tool calls and cap concurrency so you don't overload target servers.
  3. Collect only public data you need, and handle any personal data in line with the GDPR.
  4. Identify your client honestly — set a truthful User-Agent; don't impersonate someone else.

Whether a specific task is lawful depends on your jurisdiction and the target's terms — this is general information, not legal advice. See are mobile proxies legal and scraping legality in the EU.


[!NOTE]
Note: This article is general information, not legal advice. Whether a specific data-collection task is lawful depends on your jurisdiction, the target site's terms and the data involved.


FAQ

Does the proxy change how smolagents talks to the model?

No. The proxy binds to the agent's web tools — the requests they make to target sites. The model call your agent uses to reason stays on its own connection unless you deliberately route it through the proxy too. In practice you set HTTP_PROXY / HTTPS_PROXY so the fetch tools exit through the German mobile IP, and leave the model traffic alone.

Which smolagents tools honour HTTP_PROXY?

Any tool built on Python's requests — including the built-in VisitWebpageTool — reads HTTP_PROXY and HTTPS_PROXY automatically, because that's requests' default behaviour. For a custom tool that uses httpx or a browser, pass the proxy to that client directly, as in the custom-tool example above.

Why do I get a 407 error?

407 Proxy Authentication Required means the username and password didn't reach the proxy. Confirm they're in the proxy URL you exported (http://USER:PASS@PROXY_HOST:PORT). See how to fix 407 proxy authentication required.

How do I route just one tool through the German mobile IP?

Write a custom @tool that builds its own client and pass the proxy there — requests.get(url, proxies={"http": PROXY, "https": PROXY}) or httpx.Client(proxy=PROXY). Only that tool's traffic exits through the German mobile IP; everything else uses your normal connection.

HTTP or SOCKS5?

Tools built on requests work with an HTTP endpoint out of the box, which is why the examples use http://. SOCKS5 and OpenVPN are available too — for SOCKS you install requests[socks] and use a socks5:// URL. For most smolagents work, HTTP is simplest. See SOCKS5 and HTTP compared.

Do I need a rotating pool for smolagents?

No. Pool middlewares exist to pick an IP from many. With one dedicated German endpoint you point every tool at a single host and rotate on demand at the proxy — nothing to manage in the agent. See dedicated vs shared mobile proxy.


Related guides

Get Started

Give your smolagents agent a real German mobile IP to collect from. Get a German mobile proxy — HTTP/SOCKS5/OpenVPN, sticky sessions, on-demand rotation, fair-use 20 GB/day, from a transparent EU provider. Browse the plans to get started.


Get a German mobile proxy: Real 4G/5G IPs from Germany, fair-use 20 GB/day — see German 4G/5G mobile proxy options or start with a dedicated 5G proxy.

Telegram Support
Nach oben scrollen