# InvocationsHostServer

> **Class** in `langchain_azure_ai`

📖 [View in docs](https://reference.langchain.com/python/langchain-azure-ai/agents/hosting/_invoke_host/InvocationsHostServer)

Host a LangChain ``Runnable`` as the Invocations API.

## Signature

```python
InvocationsHostServer(
    self,
    graph: Runnable[GraphInputT, GraphOutputT],
    *,
    output_parser: Optional[InvocationOutputParser[GraphOutputT]] = None,
    options: Optional[ResponsesServerOptions] = None,
    app: Optional[InvocationAgentServerHost] = None,
    applicationinsights_connection_string: Optional[str] = None,
    graceful_shutdown_timeout: Optional[int] = None,
)
```

## Description

**Example:**

Create an agent graph with a checkpointer and host it on
``POST /invocations``::

    import os

    from langchain.agents import create_agent
    from langchain_openai import ChatOpenAI
    from langgraph.checkpoint.memory import MemorySaver

    from langchain_azure_ai.agents.hosting import InvocationsHostServer

    model = ChatOpenAI(
        model=os.environ.get("AZURE_AI_MODEL_DEPLOYMENT_NAME", "gpt-4o"),
    )
    graph = create_agent(model, tools=[], checkpointer=MemorySaver())

    InvocationsHostServer(graph).run(port=8088)

The host maps ``agent_session_id`` to a user-partitioned internal
``RunnableConfig.configurable.thread_id`` so follow-up turns continue
the same checkpointed conversation without colliding across users.

.. code-block:: json

    { "message": "Hello!", "stream": false }

Where:

    - ``message`` (required) — user message text, or a non-empty list containing
        a Responses-style ``function_call_output`` / ``mcp_approval_response``
        item that answers a pending LangGraph interrupt.
- ``stream`` (optional, default ``false``) — when ``true`` returns SSE
  with token deltas; when ``false`` returns a single JSON response.
    - ``background`` (optional, default ``false``) — when ``true`` starts a
        durable invocation and returns ``202``. Requires
        ``options.resilient_background=True`` and a LangGraph checkpointer.
    - ``previous_invocation_id`` (optional) — linear-chain precondition for a
        continued ``agent_session_id``.

    Pending LangGraph interrupts are exposed beside ``response`` as the same
    paired ``function_call`` and ``mcp_approval_request`` output items used by
    :class:`ResponsesHostServer`. Streaming requests emit each item as an
    ``output_item`` SSE event.

Multi-turn continuation uses the ``agent_session_id`` query param /
``x-agent-session-id`` header populated by
:class:`InvocationAgentServerHost`. The public session id remains in the
API envelope, while task and LangGraph state use an internal id derived
from the user partition and session id.

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `graph` | `Runnable[GraphInputT, GraphOutputT]` | Yes | The runnable to host. The default converters expect a LangGraph-style messages state input and output. Pass ``output_parser`` or subclass the request/output hooks for custom runnable shapes. |

## Extends

- `Generic[GraphInputT, GraphOutputT]`

## Constructors

```python
__init__(
    self,
    graph: Runnable[GraphInputT, GraphOutputT],
    *,
    output_parser: Optional[InvocationOutputParser[GraphOutputT]] = None,
    options: Optional[ResponsesServerOptions] = None,
    app: Optional[InvocationAgentServerHost] = None,
    applicationinsights_connection_string: Optional[str] = None,
    graceful_shutdown_timeout: Optional[int] = None,
) -> None
```

| Name | Type |
|------|------|
| `graph` | `Runnable[GraphInputT, GraphOutputT]` |
| `output_parser` | `Optional[InvocationOutputParser[GraphOutputT]]` |
| `options` | `Optional[ResponsesServerOptions]` |
| `app` | `Optional[InvocationAgentServerHost]` |
| `applicationinsights_connection_string` | `Optional[str]` |
| `graceful_shutdown_timeout` | `Optional[int]` |


## Properties

- `app`
- `graph`

## Methods

- [`run()`](https://reference.langchain.com/python/langchain-azure-ai/agents/hosting/_invoke_host/InvocationsHostServer/run)
- [`run_async()`](https://reference.langchain.com/python/langchain-azure-ai/agents/hosting/_invoke_host/InvocationsHostServer/run_async)
- [`parse_request()`](https://reference.langchain.com/python/langchain-azure-ai/agents/hosting/_invoke_host/InvocationsHostServer/parse_request)
- [`parse_execution_options()`](https://reference.langchain.com/python/langchain-azure-ai/agents/hosting/_invoke_host/InvocationsHostServer/parse_execution_options)
- [`build_runnable_config()`](https://reference.langchain.com/python/langchain-azure-ai/agents/hosting/_invoke_host/InvocationsHostServer/build_runnable_config)
- [`build_task_runnable_config()`](https://reference.langchain.com/python/langchain-azure-ai/agents/hosting/_invoke_host/InvocationsHostServer/build_task_runnable_config)
- [`build_input()`](https://reference.langchain.com/python/langchain-azure-ai/agents/hosting/_invoke_host/InvocationsHostServer/build_input)
- [`parse_output()`](https://reference.langchain.com/python/langchain-azure-ai/agents/hosting/_invoke_host/InvocationsHostServer/parse_output)

---

[View source on GitHub](https://github.com/langchain-ai/langchain-azure/blob/7a6a664d617264df8dcb12fcfb1bacc09f21d504/libs/azure-ai/langchain_azure_ai/agents/hosting/_invoke_host.py#L357)