Keep in mind that if you go the custom endpoint route, you need solid fallback logic in your FastAPI app. OpenAI's client handles retries nicely out of the box, but with vLLM you have to deal with connection drops and streaming timeouts manually. Here is a quick snippet we use for async streaming with httpx:
async def stream_local_llm(payload: dict):
async with httpx.AsyncClient(timeout=30.0) as client:
async with client.stream("POST", "http://localhost:8000/v1/chat/completions", json=payload) as response:
async for chunk in response.aiter_lines():
if chunk:
yield chunk
If you have strict latency SLAs, managing that infrastructure overhead yourself is the real tradeoff against just paying for the API.