---
title: prefactor_http.client module
editUrl: true
head: []
template: doc
sidebar:
  hidden: false
  attrs: {}
pagefind: true
draft: false
---

# prefactor_http.client module

HTTP client for Prefactor API.

### *class* prefactor_http.client.PrefactorHttpClient(config: [HttpClientConfig](prefactor_http.config.md#prefactor_http.config.HttpClientConfig), sdk_header: str | None = None)

Bases: `object`

Main HTTP client for interacting with the Prefactor API.

This client provides high-level methods for all API endpoints with
built-in retry logic, error handling, and idempotency support.

Usage:
: async with PrefactorHttpClient(config) as client:
  : instance = await client.agent_instances.register(…)
    span = await client.agent_spans.create(…)

#### *property* agent_instances *: [AgentInstanceClient](prefactor_http.endpoints.md#prefactor_http.endpoints.AgentInstanceClient)*

Access the agent instance endpoint client.

Provides methods to interact with agent instances:
- register: Create a new agent instance
- start: Mark an instance as started
- finish: Mark an instance as finished

### Example

instance = await client.agent_instances.register(agent_id, agent_version)

#### *property* agent_spans *: [AgentSpanClient](prefactor_http.endpoints.md#prefactor_http.endpoints.AgentSpanClient)*

Access the agent span endpoint client.

Provides methods to interact with agent spans:
- create: Create a new agent span
- finish: Mark a span as finished

### Example

span = await client.agent_spans.create(
: agent_instance_id, schema_name, payload

)

#### *property* bulk *: [BulkClient](prefactor_http.endpoints.md#prefactor_http.endpoints.BulkClient)*

Access the bulk endpoint client.

Provides methods to execute multiple queries/actions in a single request:
- execute: Execute bulk operations

### Example

response = await client.bulk.execute(bulk_request)

#### *async* close() → None

Close the HTTP session.

#### *async* request(method: str, path: str, , params: dict[str, Any] | None = None, json_data: dict[str, Any] | None = None, idempotency_key: str | None = None) → dict[str, Any]

Make an HTTP request with retry logic.

This is the public request method that wraps the core request
with retry handling.

* **Parameters:**
  * **method** – HTTP method (GET, POST, PUT, DELETE).
  * **path** – API path.
  * **params** – Query parameters.
  * **json_data** – JSON body data.
  * **idempotency_key** – Optional idempotency key.
* **Returns:**
  Parsed JSON response.
* **Raises:**
  * [**PrefactorRetryExhaustedError**](prefactor_http.md#prefactor_http.PrefactorRetryExhaustedError) – When retries are exhausted.
  * [**PrefactorApiError**](prefactor_http.md#prefactor_http.PrefactorApiError) – On API errors.