mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-17 09:34:48 +00:00
refactor(opencode): resolve Responses credentials through the shared helpers
This commit is contained in:
parent
0ddf4ff30f
commit
2ecfec7279
2 changed files with 13 additions and 35 deletions
|
|
@ -12,11 +12,12 @@ from typing import (
|
|||
Final,
|
||||
)
|
||||
|
||||
import litellm
|
||||
from litellm.llms.openai.responses.transformation import OpenAIResponsesAPIConfig
|
||||
from litellm.llms.opencode.common_utils import with_opencode_session_header
|
||||
from litellm.secret_managers.main import get_secret_str
|
||||
from litellm.types.responses.main import *
|
||||
from litellm.llms.opencode.common_utils import (
|
||||
resolve_opencode_api_base,
|
||||
resolve_opencode_api_key,
|
||||
with_opencode_session_header,
|
||||
)
|
||||
from litellm.types.router import GenericLiteLLMParams
|
||||
from litellm.types.utils import LlmProviders
|
||||
|
||||
|
|
@ -54,13 +55,7 @@ class OpenCodeGoResponsesAPIConfig(OpenAIResponsesAPIConfig):
|
|||
litellm_params: GenericLiteLLMParams | None,
|
||||
) -> dict: # mutable-ok: signature must match OpenAIResponsesAPIConfig
|
||||
litellm_params = litellm_params or GenericLiteLLMParams() # rebind-ok: default to empty params
|
||||
api_key: Final = (
|
||||
litellm_params.api_key
|
||||
or litellm.opencode_go_api_key
|
||||
or get_secret_str("OPENCODE_GO_API_KEY")
|
||||
or get_secret_str("OPENCODE_API_KEY")
|
||||
or litellm.api_key
|
||||
)
|
||||
api_key: Final = resolve_opencode_api_key("go", litellm_params.api_key)
|
||||
|
||||
if not api_key:
|
||||
raise ValueError(
|
||||
|
|
@ -76,13 +71,7 @@ class OpenCodeGoResponsesAPIConfig(OpenAIResponsesAPIConfig):
|
|||
api_base: str | None,
|
||||
litellm_params: Mapping[str, Any],
|
||||
) -> str:
|
||||
base: Final = (
|
||||
api_base
|
||||
or litellm.opencode_go_api_base
|
||||
or get_secret_str("OPENCODE_GO_API_BASE")
|
||||
or litellm.api_base
|
||||
or GO_MESSAGES_BASE
|
||||
).rstrip("/")
|
||||
base: Final = (resolve_opencode_api_base("go", api_base) or GO_MESSAGES_BASE).rstrip("/")
|
||||
|
||||
if base.endswith("/v1/responses"):
|
||||
return base
|
||||
|
|
|
|||
|
|
@ -12,10 +12,11 @@ from typing import (
|
|||
Final,
|
||||
)
|
||||
|
||||
import litellm
|
||||
from litellm.llms.openai.responses.transformation import OpenAIResponsesAPIConfig
|
||||
from litellm.secret_managers.main import get_secret_str
|
||||
from litellm.types.responses.main import *
|
||||
from litellm.llms.opencode.common_utils import (
|
||||
resolve_opencode_api_base,
|
||||
resolve_opencode_api_key,
|
||||
)
|
||||
from litellm.types.router import GenericLiteLLMParams
|
||||
from litellm.types.utils import LlmProviders
|
||||
|
||||
|
|
@ -53,13 +54,7 @@ class OpenCodeZenResponsesAPIConfig(OpenAIResponsesAPIConfig):
|
|||
litellm_params: GenericLiteLLMParams | None,
|
||||
) -> dict: # mutable-ok: signature must match OpenAIResponsesAPIConfig
|
||||
litellm_params = litellm_params or GenericLiteLLMParams() # rebind-ok: default to empty params
|
||||
api_key: Final = (
|
||||
litellm_params.api_key
|
||||
or litellm.opencode_zen_api_key
|
||||
or get_secret_str("OPENCODE_ZEN_API_KEY")
|
||||
or get_secret_str("OPENCODE_API_KEY")
|
||||
or litellm.api_key
|
||||
)
|
||||
api_key: Final = resolve_opencode_api_key("zen", litellm_params.api_key)
|
||||
|
||||
if not api_key:
|
||||
raise ValueError(
|
||||
|
|
@ -75,13 +70,7 @@ class OpenCodeZenResponsesAPIConfig(OpenAIResponsesAPIConfig):
|
|||
api_base: str | None,
|
||||
litellm_params: Mapping[str, Any],
|
||||
) -> str:
|
||||
base: Final = (
|
||||
api_base
|
||||
or litellm.opencode_zen_api_base
|
||||
or get_secret_str("OPENCODE_ZEN_API_BASE")
|
||||
or litellm.api_base
|
||||
or ZEN_MESSAGES_BASE
|
||||
).rstrip("/")
|
||||
base: Final = (resolve_opencode_api_base("zen", api_base) or ZEN_MESSAGES_BASE).rstrip("/")
|
||||
|
||||
if base.endswith("/v1/responses"):
|
||||
return base
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue