Skip to content

refactor: add _json_headers() helper to APIMixin #156

Description

@Kamilbenkirane

Summary

The same 3-line header dict construction appears 8 times across 4 provider/protocol client files.

Current Code (repeated 8 times)

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

Proposed Change

Add a one-line helper to APIMixin:

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

Each call site becomes headers = self._json_headers(). Anthropic, which adds extra headers (anthropic-version, beta), composes naturally: headers = {**self._json_headers(), config.HEADER_ANTHROPIC_VERSION: ...}.

Files to Modify

  • src/celeste/client.py (APIMixin - add method)
  • src/celeste/protocols/chatcompletions/client.py (2 call sites)
  • src/celeste/protocols/openresponses/client.py (2 call sites)
  • src/celeste/providers/cohere/chat/client.py (2 call sites)
  • src/celeste/providers/google/generate_content/client.py (2 call sites)

Rationale

8 identical 3-line constructions reduced to 8 one-line calls. The helper is trivially simple, adds no indirection complexity, and follows the existing _deep_merge utility pattern already on APIMixin.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions