[UP] X-API-Key support

This commit is contained in:
Evgeny (Krymmy) Momotov 2025-09-11 13:57:27 +03:00
parent dc8ef9b9e8
commit 3beece288e
2 changed files with 7 additions and 3 deletions

View file

@ -1,6 +1,6 @@
[project]
name = "tts_api_library"
version = "0.1.0"
version = "0.1.2"
description = ""
authors = [
{name = "Evgeny (Krymmy) Momotov",email = "evgeny.momotov@gmail.com"}

View file

@ -34,10 +34,12 @@ class TTSClient:
Синхронный клиент. Единые точки GET/POST/REQUEST.
Сессии создаются на каждый запрос.
"""
def __init__(self, base_url: str, timeout: float = 30.0, default_headers: Optional[Dict[str, str]] = None):
def __init__(self, base_url: str, timeout: float = 30.0, default_headers: Optional[Dict[str, str]] = None, api_key: Optional[str] = None):
self.base_url = base_url.rstrip("/")
self.timeout = timeout
self.default_headers = default_headers or {}
if api_key:
self.default_headers["X-API-Key"] = api_key
# ---- публичное API ----
@ -98,10 +100,12 @@ class TTSAioClient:
Асинхронный клиент. Единые точки GET/POST/REQUEST.
Сессии создаются на каждый запрос.
"""
def __init__(self, base_url: str, timeout: float = 30.0, default_headers: Optional[Dict[str, str]] = None):
def __init__(self, base_url: str, timeout: float = 30.0, default_headers: Optional[Dict[str, str]] = None, api_key: Optional[str] = None):
self.base_url = base_url.rstrip("/")
self.timeout = timeout
self.default_headers = default_headers or {}
if api_key:
self.default_headers["X-API-Key"] = api_key
# ---- публичное API ----