Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/celeste/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from celeste.exceptions import StreamingNotSupportedError
from celeste.http import HTTPClient, get_http_client
from celeste.io import Chunk, FinishReason, Input, Output, Usage
from celeste.mime_types import ApplicationMimeType
from celeste.models import Model
from celeste.parameters import ParameterMapper, Parameters
from celeste.streaming import Stream
Expand Down Expand Up @@ -52,6 +53,10 @@ def http_client(self) -> HTTPClient:
"""HTTP client with connection pooling for this provider."""
...

def _json_headers(self) -> dict[str, str]:
"""Build standard JSON request headers with auth."""
return {**self.auth.get_headers(), "Content-Type": ApplicationMimeType.JSON}

@staticmethod
def _deep_merge(
target: dict[str, Any],
Expand Down
11 changes: 2 additions & 9 deletions src/celeste/protocols/chatcompletions/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from celeste.client import APIMixin
from celeste.core import UsageField
from celeste.io import FinishReason
from celeste.mime_types import ApplicationMimeType

from . import config

Expand Down Expand Up @@ -79,10 +78,7 @@ async def _make_request(
if endpoint is None:
endpoint = self._default_endpoint

headers = {
**self.auth.get_headers(),
"Content-Type": ApplicationMimeType.JSON,
}
headers = self._json_headers()

response = await self.http_client.post(
self._build_url(endpoint),
Expand All @@ -104,10 +100,7 @@ def _make_stream_request(
if endpoint is None:
endpoint = self._default_endpoint

headers = {
**self.auth.get_headers(),
"Content-Type": ApplicationMimeType.JSON,
}
headers = self._json_headers()

return self.http_client.stream_post(
self._build_url(endpoint, streaming=True),
Expand Down
11 changes: 2 additions & 9 deletions src/celeste/protocols/openresponses/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from celeste.client import APIMixin
from celeste.core import UsageField
from celeste.io import FinishReason
from celeste.mime_types import ApplicationMimeType

from . import config

Expand Down Expand Up @@ -79,10 +78,7 @@ async def _make_request(
if endpoint is None:
endpoint = self._default_endpoint

headers = {
**self.auth.get_headers(),
"Content-Type": ApplicationMimeType.JSON,
}
headers = self._json_headers()

response = await self.http_client.post(
self._build_url(endpoint),
Expand All @@ -104,10 +100,7 @@ def _make_stream_request(
if endpoint is None:
endpoint = self._default_endpoint

headers = {
**self.auth.get_headers(),
"Content-Type": ApplicationMimeType.JSON,
}
headers = self._json_headers()

return self.http_client.stream_post(
self._build_url(endpoint, streaming=True),
Expand Down
12 changes: 2 additions & 10 deletions src/celeste/providers/bfl/images/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,7 @@ async def _make_request(
2. Poll polling_url until Ready/Failed
3. Return response with _submit_metadata for usage parsing
"""
auth_headers = self.auth.get_headers()
headers = {
**auth_headers,
"Content-Type": ApplicationMimeType.JSON,
"Accept": ApplicationMimeType.JSON,
}
headers = {**self._json_headers(), "Accept": ApplicationMimeType.JSON}

if endpoint is None:
endpoint = config.BFLImagesEndpoint.CREATE_IMAGE
Expand All @@ -77,10 +72,7 @@ async def _make_request(

# Phase 2: Poll for completion
start_time = time.monotonic()
poll_headers = {
**auth_headers,
"Accept": ApplicationMimeType.JSON,
}
poll_headers = {**self.auth.get_headers(), "Accept": ApplicationMimeType.JSON}

while True:
elapsed = time.monotonic() - start_time
Expand Down
11 changes: 2 additions & 9 deletions src/celeste/providers/byteplus/images/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from celeste.client import APIMixin
from celeste.core import UsageField
from celeste.io import FinishReason
from celeste.mime_types import ApplicationMimeType

from . import config

Expand Down Expand Up @@ -57,10 +56,7 @@ async def _make_request(
if endpoint is None:
endpoint = config.BytePlusImagesEndpoint.CREATE_IMAGE

headers = {
**self.auth.get_headers(),
"Content-Type": ApplicationMimeType.JSON,
}
headers = self._json_headers()

response = await self.http_client.post(
f"{config.BASE_URL}{endpoint}",
Expand All @@ -82,10 +78,7 @@ def _make_stream_request(
if endpoint is None:
endpoint = config.BytePlusImagesEndpoint.CREATE_IMAGE

headers = {
**self.auth.get_headers(),
"Content-Type": ApplicationMimeType.JSON,
}
headers = self._json_headers()

return self.http_client.stream_post(
f"{config.BASE_URL}{endpoint}",
Expand Down
7 changes: 1 addition & 6 deletions src/celeste/providers/byteplus/videos/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from celeste.core import UsageField
from celeste.exceptions import StreamingNotSupportedError
from celeste.io import FinishReason
from celeste.mime_types import ApplicationMimeType

from . import config

Expand Down Expand Up @@ -67,11 +66,7 @@ async def _make_request(
2. Poll CONTENT_STATUS endpoint until succeeded/failed/canceled
3. Return response with final status data
"""
auth_headers = self.auth.get_headers()
headers = {
**auth_headers,
"Content-Type": ApplicationMimeType.JSON,
}
headers = self._json_headers()

if endpoint is None:
endpoint = config.BytePlusVideosEndpoint.CREATE_VIDEO
Expand Down
11 changes: 2 additions & 9 deletions src/celeste/providers/cohere/chat/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from celeste.client import APIMixin
from celeste.core import UsageField
from celeste.io import FinishReason
from celeste.mime_types import ApplicationMimeType

from . import config

Expand Down Expand Up @@ -59,10 +58,7 @@ async def _make_request(
if endpoint is None:
endpoint = config.CohereChatEndpoint.CREATE_CHAT

headers = {
**self.auth.get_headers(),
"Content-Type": ApplicationMimeType.JSON,
}
headers = self._json_headers()

response = await self.http_client.post(
f"{config.BASE_URL}{endpoint}",
Expand All @@ -84,10 +80,7 @@ def _make_stream_request(
if endpoint is None:
endpoint = config.CohereChatEndpoint.CREATE_CHAT

headers = {
**self.auth.get_headers(),
"Content-Type": ApplicationMimeType.JSON,
}
headers = self._json_headers()

return self.http_client.stream_post(
f"{config.BASE_URL}{endpoint}",
Expand Down
12 changes: 3 additions & 9 deletions src/celeste/providers/elevenlabs/text_to_speech/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from celeste.client import APIMixin
from celeste.io import FinishReason
from celeste.mime_types import ApplicationMimeType, AudioMimeType
from celeste.mime_types import AudioMimeType

from . import config

Expand Down Expand Up @@ -55,10 +55,7 @@ async def _make_request(
endpoint = config.ElevenLabsTextToSpeechEndpoint.CREATE_SPEECH
endpoint = endpoint.format(voice_id=voice_id)

headers = {
**self.auth.get_headers(),
"Content-Type": ApplicationMimeType.JSON,
}
headers = self._json_headers()

response = await self.http_client.post(
f"{config.BASE_URL}{endpoint}",
Expand Down Expand Up @@ -96,10 +93,7 @@ def _make_stream_request(
endpoint = config.ElevenLabsTextToSpeechEndpoint.STREAM_SPEECH
endpoint = endpoint.format(voice_id=voice_id)

headers = {
**self.auth.get_headers(),
"Content-Type": ApplicationMimeType.JSON,
}
headers = self._json_headers()

return self._stream_binary_audio(
f"{config.BASE_URL}{endpoint}",
Expand Down
6 changes: 1 addition & 5 deletions src/celeste/providers/google/cloud_tts/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from celeste.client import APIMixin
from celeste.exceptions import StreamingNotSupportedError
from celeste.io import FinishReason
from celeste.mime_types import ApplicationMimeType

from ..auth import GoogleADC
from . import config
Expand Down Expand Up @@ -67,10 +66,7 @@ async def _make_request(
if endpoint is None:
endpoint = config.GoogleCloudTTSEndpoint.CREATE_SPEECH

headers = {
**self.auth.get_headers(),
"Content-Type": ApplicationMimeType.JSON,
}
headers = self._json_headers()

response = await self.http_client.post(
f"{config.BASE_URL}{endpoint}",
Expand Down
6 changes: 1 addition & 5 deletions src/celeste/providers/google/embeddings/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from celeste.client import APIMixin
from celeste.exceptions import StreamingNotSupportedError
from celeste.io import FinishReason
from celeste.mime_types import ApplicationMimeType

from ..auth import GoogleADC
from . import config
Expand Down Expand Up @@ -96,10 +95,7 @@ async def _make_request(
if endpoint is None:
endpoint = endpoint_template

headers = {
**self.auth.get_headers(),
"Content-Type": ApplicationMimeType.JSON,
}
headers = self._json_headers()

response = await self.http_client.post(
self._build_url(endpoint),
Expand Down
11 changes: 2 additions & 9 deletions src/celeste/providers/google/generate_content/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from celeste.client import APIMixin
from celeste.core import UsageField
from celeste.io import FinishReason
from celeste.mime_types import ApplicationMimeType

from ..auth import GoogleADC
from . import config
Expand Down Expand Up @@ -70,10 +69,7 @@ async def _make_request(
if endpoint is None:
endpoint = config.GoogleGenerateContentEndpoint.GENERATE_CONTENT

headers = {
**self.auth.get_headers(),
"Content-Type": ApplicationMimeType.JSON,
}
headers = self._json_headers()
response = await self.http_client.post(
url=self._build_url(endpoint),
headers=headers,
Expand All @@ -94,10 +90,7 @@ def _make_stream_request(
if endpoint is None:
endpoint = config.GoogleGenerateContentEndpoint.STREAM_GENERATE_CONTENT

headers = {
**self.auth.get_headers(),
"Content-Type": ApplicationMimeType.JSON,
}
headers = self._json_headers()
return self.http_client.stream_post(
url=self._build_url(endpoint),
headers=headers,
Expand Down
6 changes: 1 addition & 5 deletions src/celeste/providers/google/imagen/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from celeste.core import UsageField
from celeste.exceptions import StreamingNotSupportedError
from celeste.io import FinishReason
from celeste.mime_types import ApplicationMimeType

from ..auth import GoogleADC
from . import config
Expand Down Expand Up @@ -67,10 +66,7 @@ async def _make_request(
if endpoint is None:
endpoint = config.GoogleImagenEndpoint.CREATE_IMAGE

headers = {
**self.auth.get_headers(),
"Content-Type": ApplicationMimeType.JSON,
}
headers = self._json_headers()
response = await self.http_client.post(
self._build_url(endpoint),
headers=headers,
Expand Down
11 changes: 2 additions & 9 deletions src/celeste/providers/google/interactions/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from celeste.client import APIMixin
from celeste.core import UsageField
from celeste.io import FinishReason
from celeste.mime_types import ApplicationMimeType

from . import config

Expand Down Expand Up @@ -66,10 +65,7 @@ async def _make_request(
if endpoint is None:
endpoint = config.GoogleInteractionsEndpoint.CREATE_INTERACTION

headers = {
**self.auth.get_headers(),
"Content-Type": ApplicationMimeType.JSON,
}
headers = self._json_headers()
response = await self.http_client.post(
f"{config.BASE_URL}{endpoint}",
headers=headers,
Expand All @@ -90,10 +86,7 @@ def _make_stream_request(
if endpoint is None:
endpoint = config.GoogleInteractionsEndpoint.STREAM_INTERACTION

headers = {
**self.auth.get_headers(),
"Content-Type": ApplicationMimeType.JSON,
}
headers = self._json_headers()
return self.http_client.stream_post(
f"{config.BASE_URL}{endpoint}",
headers=headers,
Expand Down
12 changes: 2 additions & 10 deletions src/celeste/providers/google/veo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from celeste.client import APIMixin
from celeste.exceptions import StreamingNotSupportedError
from celeste.io import FinishReason
from celeste.mime_types import ApplicationMimeType

from ..auth import GoogleADC
from . import config
Expand Down Expand Up @@ -72,10 +71,7 @@ async def _make_poll_request(self, operation_name: str) -> dict[str, Any]:
Vertex AI uses POST to fetchPredictOperation with operationName in body.
AI Studio uses GET to /v1beta/{operation_name}.
"""
headers = {
**self.auth.get_headers(),
"Content-Type": ApplicationMimeType.JSON,
}
headers = self._json_headers()
poll_url = self._build_poll_url(operation_name)

if isinstance(self.auth, GoogleADC):
Expand Down Expand Up @@ -117,11 +113,7 @@ async def _make_request(
if endpoint is None:
endpoint = config.GoogleVeoEndpoint.CREATE_VIDEO

auth_headers = self.auth.get_headers()
headers = {
**auth_headers,
"Content-Type": ApplicationMimeType.JSON,
}
headers = self._json_headers()

logger.info(f"Initiating video generation with model {self.model.id}")
response = await self.http_client.post(
Expand Down
Loading
Loading