"""88API AI provider — OpenAI-compatible API (Chinese reseller gateway).

API key obtained from: https://www.88api.dev/
Supports: gpt-4o, gpt-4-turbo, claude-3-5-sonnet, and other models.
"""

from __future__ import annotations

import openai

from .base import AIProvider
from .base_provider import BaseAPIProvider


class API88Provider(BaseAPIProvider, AIProvider):
    """88API provider — OpenAI-compatible gateway for Chinese developers."""

    name = "88api"
    BASE_URL = "https://api.88api.dev/v1/"
    ENV_VAR = "API88_API_KEY"
    DEFAULT_MODEL = "o3-mini"

    def _create_client(self) -> openai.OpenAI:
        http_client = self._make_http_client(timeout=90.0)
        kwargs = dict(
            api_key=self.api_key,
            base_url=self.BASE_URL,
            timeout=90.0,  # Extended for China: packet loss requires longer timeouts
        )
        if http_client:
            kwargs["http_client"] = http_client
        return openai.OpenAI(**kwargs)
