Use SettleGrid Tools with Hugging Face smolagents
smolagents natively supports MCP via ToolCollection.from_mcp(). This guide shows how to point smolagents at SettleGrid's discovery server to discover, purchase, and use paid AI tools directly from your Python agents.
In this guide
Install smolagents
Install the smolagents package with MCP support. smolagents is Hugging Face's lightweight agent framework that supports MCP tool collections natively. Run pip install smolagents[mcp] to install the package with all MCP dependencies. You also need Python 3.10 or later.
If you do not have a SettleGrid account yet, sign up at settlegrid.ai/register to get your API key. You will need a consumer API key (starts with sg_) for the tools you want to use. Each tool on SettleGrid has its own API key, which you can generate from the tool's page in your dashboard.
Verify your installation by running python -c "from smolagents import ToolCollection; print('OK')". If this succeeds, you are ready to connect smolagents to SettleGrid.
Configure MCP Connection to SettleGrid
smolagents connects to MCP servers using the ToolCollection.from_mcp() method. SettleGrid's Discovery Server exposes tools via the MCP protocol, so you can point smolagents directly at it. The connection uses Server-Sent Events (SSE) transport, which smolagents supports out of the box.
Set up the connection with your SettleGrid API key. The Discovery Server URL is https://settlegrid.ai/api/mcp/sse and your API key goes in the headers. smolagents passes these headers automatically on every tool call, so SettleGrid can authenticate your requests and track billing.
You can optionally filter which tools smolagents discovers by passing query parameters to the SSE URL. For example, https://settlegrid.ai/api/mcp/sse?category=data only discovers data tools. This keeps your agent focused and prevents it from seeing irrelevant tools.
Run Your Agent
Create a smolagents CodeAgent or ToolCallingAgent with your SettleGrid tools. The agent will see the tool descriptions surfaced by SettleGrid and can call any tool it needs. Each tool call is routed through the SettleGrid proxy, which handles authentication, metering, and billing automatically.
The agent works exactly like it does with any other MCP tool collection. You do not need to handle billing, authentication, or error retries — SettleGrid manages all of that. Your agent simply calls tools and gets results. If a tool call fails due to insufficient balance, SettleGrid returns a clear error message that the agent can interpret.
For production use, set up error handling around your agent runs. If your SettleGrid balance runs out, tool calls will return 402 errors. Your application should catch these and either top up the balance automatically (via the SettleGrid API) or notify the user that more funds are needed.
View Billing in Your Dashboard
After your agent runs, visit the SettleGrid dashboard at settlegrid.ai/dashboard to see every tool call, its cost, and the response time. The dashboard shows real-time usage metrics, daily spend, and per-tool breakdowns. You can set spending alerts to get notified when your usage exceeds a threshold.
Each invocation is logged with the tool name, input (redacted for privacy), cost in cents, latency, and status. You can export this data as CSV for accounting or integrate it with your observability stack via the SettleGrid API.
smolagents does not need any special configuration for billing — it is handled entirely by the SettleGrid proxy. The per-call cost is determined by the tool's pricing configuration, and you only pay for successful calls. Failed calls (upstream errors, timeouts) are not charged.
Code Examples
Connect smolagents to SettleGrid
Pythonfrom smolagents import ToolCollection, CodeAgent, HfApiModel
# Connect to SettleGrid's MCP discovery server
tools = ToolCollection.from_mcp(
"https://settlegrid.ai/api/mcp/sse",
headers={"x-api-key": "sg_your_api_key_here"}
)
# Create an agent with discovered tools
model = HfApiModel("Qwen/Qwen2.5-Coder-32B-Instruct")
agent = CodeAgent(tools=tools, model=model)
# Run the agent — tool calls are billed automatically
result = agent.run("What is the current weather in Tokyo?")
print(result)Filter tools by category
Pythonfrom smolagents import ToolCollection, ToolCallingAgent, HfApiModel
# Only discover data tools
tools = ToolCollection.from_mcp(
"https://settlegrid.ai/api/mcp/sse?category=data",
headers={"x-api-key": "sg_your_api_key_here"}
)
# List available tools
for tool in tools:
print(f"{tool.name}: {tool.description}")
# Create agent and run queries
model = HfApiModel("Qwen/Qwen2.5-Coder-32B-Instruct")
agent = ToolCallingAgent(tools=tools, model=model)
result = agent.run("Enrich the company domain example.com")
print(result)Ready to integrate?
Sign up for SettleGrid, get your API key, and start using paid tools in smolagents. Free tier includes 50,000 operations per month.