ApiFuseApiFuse
Guide

FastAPI integration

Use ApiFuse generated Pydantic artifacts from server-side FastAPI code.

FastAPI integration

Use Developer MCP to fetch the operation contract and generated Pydantic artifacts, then call ApiFuse from your FastAPI server. Keep ApiFuse credentials in server configuration and validate both request and response payloads.

1. Generate or copy Pydantic models

Ask your coding agent to call apifuse_dev_get_schema_bundle for the pydantic target and place the generated models in a server-side package, for example app/apifuse_generated/weather.py.

2. Call ApiFuse from an API route

# app/routes/weather.py
import os

import httpx
from fastapi import APIRouter, HTTPException

from app.apifuse_generated.weather import (
    ShortForecastInput,
    ShortForecastOutput,
)

router = APIRouter()


@router.post("/weather", response_model=ShortForecastOutput)
async def weather(input_model: ShortForecastInput) -> ShortForecastOutput:
    api_key = os.environ["APIFUSE_API_KEY"]

    async with httpx.AsyncClient(timeout=15.0) as client:
        response = await client.post(
            "https://api.apifuse.com/v1/kma-forecast/short-forecast",
            headers={"Authorization": f"Bearer {api_key}"},
            json=input_model.model_dump(mode="json"),
        )

    if response.status_code >= 400:
        raise HTTPException(status_code=502, detail="apifuse_request_failed")

    return ShortForecastOutput.model_validate(response.json())

3. Operational guidance

  • Store ApiFuse API keys in server-side environment or secret management.
  • Validate outbound input and inbound output with generated Pydantic models.
  • Return application-specific response shapes to browsers and mobile clients.
  • Do not expose provider credentials, tenant auth mapping, or canonical Connection identifiers to clients.
  • Monitor bundleHash and targetArtifactHash in CI so generated models are reviewed when schemas change.

Developer MCP boundary

Gateway MCP apifuse_dev_* tools can provide schemas, warnings, and integration snippets for FastAPI. They do not execute provider operations, refresh credentials, or mutate tenant connections.

On this page