Skip to content

invoke and ainvoke

invoke(input) blocks the current Python thread until one result is ready. await ainvoke(input) lets an async application yield control while it waits.

# A command-line script
reply = model.invoke("Summarize incident INC-104")
# An async FastAPI route or worker
async def summarize(ticket: str):
reply = await model.ainvoke(f"Summarize {ticket}")
return {"summary": reply.text}

await is Python syntax. It does not mean “retry,” “sleep,” or “run in parallel.” The base Runnable async implementation may call synchronous code in a thread pool; a subclass can provide native async behavior.

Calling invoke() inside an async web handler can block its event-loop thread. Calling ainvoke() does not remove provider rate limits, connection limits, or the need for a timeout.

Chat models · batch and abatch · Retries and backoff