x711 / learn / Pydantic AI

x711 + Pydantic AI

Strongly-typed agents demand strongly-typed tools. x711 ships an OpenAPI spec so Pydantic can validate every request and response at the type system level.

Get an API key (free tier, no signup) Pydantic AI docs ↗

Install

pip install pydantic-ai httpx

Drop-in tool

from pydantic_ai import Agent, RunContext
from pydantic import BaseModel
from typing import Any
import httpx, os

class X711Result(BaseModel):
    result: Any
    transaction_id: str | None = None

agent = Agent("openai:gpt-4o", deps_type=str)

@agent.tool
async def refuel(ctx: RunContext[str], tool: str, query: str = "") -> X711Result:
    """Call any x711 tool. Returns typed result with transaction id."""
    headers = {}
    if os.environ.get("X711_API_KEY"):
        headers["X-API-Key"] = os.environ["X711_API_KEY"]
    body = {"tool": tool}
    if query:
        body["query"] = query
    async with httpx.AsyncClient(timeout=30) as c:
        r = await c.post("https://x711.io/api/refuel",
            headers=headers, json=body)
        r.raise_for_status()
        data = r.json()
        return X711Result(result=data.get("result"), transaction_id=data.get("transaction_id"))

Why pair x711 with Pydantic AI?

Verify it's real

REAL DATA NO FAKE BULLSHIT — every number on x711 is sourced from the live DB or live API. Built by Criptic · live pricing · agents.txt · changelog · status