Skip to content

Instantly share code, notes, and snippets.

@samirsaci
Created November 9, 2025 12:59
Show Gist options
  • Select an option

  • Save samirsaci/e49702cd01720e5bb8bf65dff7477679 to your computer and use it in GitHub Desktop.

Select an option

Save samirsaci/e49702cd01720e5bb8bf65dff7477679 to your computer and use it in GitHub Desktop.
AI Agents Budget Planning - FastAPI Calling
import os, logging, httpx
import logging
from app.models.budagent_models import LaunchParamsBudget
from app.utils.config_loader import load_config
logger = logging.getLogger(__name__)
API = os.getenv("API_URL")
LAUNCH = f"{API}/budget/launch_budget"
async def run_budget_api(params: LaunchParamsBudget,
session_id: str = "test_agent") -> dict:
payload = {
"objective": params.objective,
"budget_year1": params.budget_year1,
"budget_year2": params.budget_year2,
"budget_year3": params.budget_year3,
"set_min_budget": params.set_min_budget,
"min_budget_objective": params.min_budget_objective,
"min_budget_perc": params.min_budget_perc,
}
try:
async with httpx.AsyncClient(timeout=httpx.Timeout(5, read=30)) as c:
r = await c.post(LAUNCH,
json=payload,
headers={"session_id": session_id})
r.raise_for_status()
return r.json()
except httpx.HTTPError as e:
logger.error("[BudgetAgent]: API call failed: %s", e)
code = getattr(e.response, "status_code", "")
return {"error": f"{code} {e}"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment