Httpx Client
infra.llm.httpx_client
Summary
HTTP client ports for OpenAI-compatible chat completion endpoints.
Provide synchronous and asynchronous httpx wrappers that issue chat completion requests with bearer authentication.
Classes
AsyncClientPort
Asynchronous httpx client for chat completion APIs.
Attributes:
| Name | Type | Description |
|---|---|---|
api_key |
str
|
Bearer token used for authentication. |
endpoint |
str
|
Base URL of the completions API. |
timeout |
float
|
Request timeout in seconds. |
_http_client |
AsyncClient
|
Underlying asynchronous HTTP client. |
Initialize the asynchronous client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key |
str
|
Bearer token used for authentication. |
''
|
endpoint |
str
|
Base URL of the completions API. |
''
|
timeout |
float
|
Request timeout in seconds. |
60.0
|
Functions
chat_completion
async
Send an asynchronous chat completion request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model |
str
|
Model identifier to invoke. |
required |
messages |
list
|
Chat messages in API format. |
required |
temperature |
float
|
Sampling temperature. |
0.0
|
max_tokens |
int
|
Maximum tokens to generate. |
4096
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Decoded JSON response body. |
SyncClientPort
Synchronous httpx client for chat completion APIs.
Attributes:
| Name | Type | Description |
|---|---|---|
api_key |
str
|
Bearer token used for authentication. |
endpoint |
str
|
Base URL of the completions API. |
timeout |
float
|
Request timeout in seconds. |
_client |
Client
|
Underlying synchronous HTTP client. |
Initialize the synchronous client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key |
str
|
Bearer token used for authentication. |
''
|
endpoint |
str
|
Base URL of the completions API. |
''
|
timeout |
float
|
Request timeout in seconds. |
60.0
|
Functions
chat_completion
Send a chat completion request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model |
str
|
Model identifier to invoke. |
required |
messages |
list
|
Chat messages in API format. |
required |
temperature |
float
|
Sampling temperature. |
0.0
|
max_tokens |
int
|
Maximum tokens to generate. |
4096
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Decoded JSON response body. |