mirror of
https://github.com/hanzoai/python-sdk.git
synced 2026-10-26 11:49:36 +00:00
chore: update SDK client, memory docs, and tests
This commit is contained in:
@@ -12,7 +12,7 @@ These capabilities support more personalized, contextually aware, and human-like
|
||||
|
||||
### Authentication
|
||||
|
||||
* **Production**: All endpoints require an API key provided via the `x-hanzo-api-key` HTTP header or set in the `HANZO_API_KEY` environment variable.
|
||||
* **Production**: All endpoints require an API key provided via the `x-api-key` HTTP header or set in the `HANZO_API_KEY` environment variable.
|
||||
* **Local Development**: Authentication can be disabled when running locally by setting `DISABLE_AUTH=true` or omitting the header.
|
||||
|
||||
> **Note:** All endpoints are RESTful and expect JSON request bodies with **lowercase** key names (e.g., `userid`, `messagecontent`). The `userid` parameter is **mandatory** for most endpoints; it partitions data per user to ensure multi-tenancy and security.
|
||||
@@ -294,7 +294,7 @@ CREATE TABLE fact_relations (
|
||||
|
||||
### Endpoints
|
||||
|
||||
All endpoints require `userid` and either the `x-hanzo-api-key` header or `HANZO_API_KEY` environment variable (unless `DISABLE_AUTH=true`).
|
||||
All endpoints require `userid` and either the `x-api-key` header or `HANZO_API_KEY` environment variable (unless `DISABLE_AUTH=true`).
|
||||
|
||||
#### 1. POST /v1/knowledge/bases/create
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ Authorization: Bearer YOUR_API_KEY
|
||||
```
|
||||
|
||||
Alternative authentication methods:
|
||||
- `x-hanzo-api-key` header
|
||||
- `x-api-key` header
|
||||
- `x-api-key` header
|
||||
- `apikey` in request body (for backwards compatibility)
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ def get_api_key(
|
||||
|
||||
Checks in order:
|
||||
1. Authorization header (Bearer token)
|
||||
2. x-hanzo-api-key header
|
||||
2. x-api-key header
|
||||
3. x-api-key header
|
||||
4. apikey in JSON body
|
||||
|
||||
@@ -33,7 +33,7 @@ def get_api_key(
|
||||
return credentials.credentials
|
||||
|
||||
# Check custom headers
|
||||
api_key = request.headers.get("x-hanzo-api-key")
|
||||
api_key = request.headers.get("x-api-key")
|
||||
if api_key:
|
||||
return api_key
|
||||
|
||||
|
||||
+10
-10
@@ -426,9 +426,9 @@ class BaseClient(Generic[_HttpxClientT, _DefaultStreamT]):
|
||||
# Don't set these headers if they were already set or removed by the caller. We check
|
||||
# `custom_headers`, which can contain `Omit()`, instead of `headers` to account for the removal case.
|
||||
lower_custom_headers = [header.lower() for header in custom_headers]
|
||||
if "x-hanzo-retry-count" not in lower_custom_headers:
|
||||
headers["x-hanzo-retry-count"] = str(retries_taken)
|
||||
if "x-hanzo-read-timeout" not in lower_custom_headers:
|
||||
if "x-sdk-retry-count" not in lower_custom_headers:
|
||||
headers["x-sdk-retry-count"] = str(retries_taken)
|
||||
if "x-sdk-read-timeout" not in lower_custom_headers:
|
||||
timeout = (
|
||||
self.timeout
|
||||
if isinstance(options.timeout, NotGiven)
|
||||
@@ -437,7 +437,7 @@ class BaseClient(Generic[_HttpxClientT, _DefaultStreamT]):
|
||||
if isinstance(timeout, Timeout):
|
||||
timeout = timeout.read
|
||||
if timeout is not None:
|
||||
headers["x-hanzo-read-timeout"] = str(timeout)
|
||||
headers["x-sdk-read-timeout"] = str(timeout)
|
||||
|
||||
return headers
|
||||
|
||||
@@ -1984,12 +1984,12 @@ def get_platform() -> Platform:
|
||||
@lru_cache(maxsize=None)
|
||||
def platform_headers(version: str, *, platform: Platform | None) -> Dict[str, str]:
|
||||
return {
|
||||
"X-Hanzo-Lang": "python",
|
||||
"X-Hanzo-Package-Version": version,
|
||||
"X-Hanzo-OS": str(platform or get_platform()),
|
||||
"X-Hanzo-Arch": str(get_architecture()),
|
||||
"X-Hanzo-Runtime": get_python_runtime(),
|
||||
"X-Hanzo-Runtime-Version": get_python_version(),
|
||||
"X-SDK-Lang": "python",
|
||||
"X-SDK-Package-Version": version,
|
||||
"X-SDK-OS": str(platform or get_platform()),
|
||||
"X-SDK-Arch": str(get_architecture()),
|
||||
"X-SDK-Runtime": get_python_runtime(),
|
||||
"X-SDK-Runtime-Version": get_python_version(),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -488,7 +488,7 @@ class Hanzo(SyncAPIClient):
|
||||
def default_headers(self) -> dict[str, str | Omit]:
|
||||
return {
|
||||
**super().default_headers,
|
||||
"X-Hanzo-Async": "false",
|
||||
"X-SDK-Async": "false",
|
||||
**self._custom_headers,
|
||||
}
|
||||
|
||||
@@ -932,7 +932,7 @@ class AsyncHanzo(AsyncAPIClient):
|
||||
def default_headers(self) -> dict[str, str | Omit]:
|
||||
return {
|
||||
**super().default_headers,
|
||||
"X-Hanzo-Async": f"async:{get_async_library()}",
|
||||
"X-SDK-Async": f"async:{get_async_library()}",
|
||||
**self._custom_headers,
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import httpx
|
||||
|
||||
RAW_RESPONSE_HEADER = "X-Hanzo-Raw-Response"
|
||||
RAW_RESPONSE_HEADER = "X-SDK-Raw-Response"
|
||||
OVERRIDE_CAST_TO_HEADER = "____hanzo_override_cast_to"
|
||||
|
||||
# default timeout is 1 minute
|
||||
|
||||
Vendored
+2
-2
@@ -64,7 +64,7 @@ class CacheResource(SyncAPIResource):
|
||||
"""Endpoint for deleting a key from the cache.
|
||||
|
||||
All responses from hanzo proxy
|
||||
have `x-hanzo-cache-key` in the headers
|
||||
have `x-cache-key` in the headers
|
||||
|
||||
Parameters:
|
||||
|
||||
@@ -180,7 +180,7 @@ class AsyncCacheResource(AsyncAPIResource):
|
||||
"""Endpoint for deleting a key from the cache.
|
||||
|
||||
All responses from hanzo proxy
|
||||
have `x-hanzo-cache-key` in the headers
|
||||
have `x-cache-key` in the headers
|
||||
|
||||
Parameters:
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class InfoResource(SyncAPIResource):
|
||||
descriptions (except api key and api base)
|
||||
|
||||
Parameters: hanzo_model_id: Optional[str] = None (this is the value of
|
||||
`x-hanzo-model-id` returned in response headers)
|
||||
`x-model-id` returned in response headers)
|
||||
|
||||
- When hanzo_model_id is passed, it will return the info for that specific model
|
||||
- When hanzo_model_id is not passed, it will return the info for all models
|
||||
@@ -148,7 +148,7 @@ class AsyncInfoResource(AsyncAPIResource):
|
||||
descriptions (except api key and api base)
|
||||
|
||||
Parameters: hanzo_model_id: Optional[str] = None (this is the value of
|
||||
`x-hanzo-model-id` returned in response headers)
|
||||
`x-model-id` returned in response headers)
|
||||
|
||||
- When hanzo_model_id is passed, it will return the info for that specific model
|
||||
- When hanzo_model_id is not passed, it will return the info for all models
|
||||
|
||||
Reference in New Issue
Block a user