Authentication helpers for various LLM providers.
Submodules:
- github_auth: GitHub Copilot authentication (with enterprise support)
- openai_codex_auth: OpenAI Codex (ChatGPT Plus/Pro) OAuth authentication
- zen_auth: OpenCode Zen API key authentication
- poe_auth: Poe OAuth / API key authentication
AuthInfo
module-attribute
Authentication credentials (discriminated union on 'type').
ApiAuthInfo
Bases: BaseModel
API key authentication credentials.
Source code in src/llmling_models/auth/models.py
| class ApiAuthInfo(BaseModel):
"""API key authentication credentials."""
type: Literal["api"]
"""Auth type discriminator."""
key: str
"""API key."""
|
OAuthAuthInfo
Bases: BaseModel
OAuth authentication credentials.
Source code in src/llmling_models/auth/models.py
| class OAuthAuthInfo(BaseModel):
"""OAuth authentication credentials."""
type: Literal["oauth"]
"""Auth type discriminator."""
refresh: str
"""Refresh token."""
access: str
"""Access token."""
expires: int
"""Token expiry timestamp."""
account_id: str | None = None
"""Optional account identifier."""
enterprise_url: str | None = None
"""Optional enterprise URL."""
|
access
instance-attribute
account_id
class-attribute
instance-attribute
account_id: str | None = None
Optional account identifier.
enterprise_url
class-attribute
instance-attribute
enterprise_url: str | None = None
expires
instance-attribute
refresh
instance-attribute
ProviderAuthAuthorization
Bases: BaseModel
Response from starting a provider OAuth flow.
Source code in src/llmling_models/auth/models.py
| class ProviderAuthAuthorization(BaseModel):
"""Response from starting a provider OAuth flow."""
url: str
"""URL to open in browser for authorization."""
method: Literal["auto", "code"]
"""Authorization method."""
instructions: str
"""Instructions to display to the user."""
|
instructions
instance-attribute
Instructions to display to the user.
method
instance-attribute
method: Literal['auto', 'code']
url
instance-attribute
URL to open in browser for authorization.
ProviderAuthService
dataclass
Registry of provider auth backends.
Mirrors opencode's ProviderAuth namespace — routes call service methods
instead of containing provider-specific logic.
Source code in src/llmling_models/auth/auth_service.py
| @dataclass
class ProviderAuthService:
"""Registry of provider auth backends.
Mirrors opencode's ProviderAuth namespace — routes call service methods
instead of containing provider-specific logic.
"""
_backends: dict[str, ProviderAuthBackend] = field(default_factory=dict)
def register(self, backend: ProviderAuthBackend) -> None:
"""Register an auth backend."""
self._backends[backend.provider_id] = backend
def get_backend(self, provider_id: str) -> ProviderAuthBackend:
"""Get backend by provider ID.
Raises:
KeyError: If provider_id is not registered.
"""
try:
return self._backends[provider_id]
except KeyError:
raise KeyError(f"Unknown provider: {provider_id}") from None
def methods(self) -> dict[str, list[ProviderAuthMethod]]:
"""Return auth methods for all registered providers."""
return {pid: backend.methods() for pid, backend in self._backends.items()}
async def authorize(self, provider_id: str, method: int = 0) -> ProviderAuthAuthorization:
"""Start auth flow for a provider."""
return await self.get_backend(provider_id).authorize(method)
async def callback(
self,
provider_id: str,
*,
code: str | None = None,
device_code: str | None = None,
verifier: str | None = None,
) -> bool:
"""Handle auth callback for a provider."""
return await self.get_backend(provider_id).callback(
code=code, device_code=device_code, verifier=verifier
)
async def set_credentials(self, provider_id: str, info: AuthInfo) -> bool:
"""Set credentials for a provider."""
return await self.get_backend(provider_id).set_credentials(info)
async def remove_credentials(self, provider_id: str) -> bool:
"""Remove credentials for a provider."""
return await self.get_backend(provider_id).remove_credentials()
@classmethod
def create_default(cls) -> Self:
"""Create auth service with built-in providers."""
from llmling_models.auth.github_auth import CopilotAuthBackend
from llmling_models.auth.openai_codex_auth import OpenAICodexAuthBackend
from llmling_models.auth.poe_auth import PoeAuthBackend
from llmling_models.auth.zen_auth import ZenAuthBackend
service = cls()
service.register(CopilotAuthBackend())
service.register(OpenAICodexAuthBackend())
service.register(PoeAuthBackend())
service.register(ZenAuthBackend())
return service
|
authorize
async
Start auth flow for a provider.
Source code in src/llmling_models/auth/auth_service.py
| async def authorize(self, provider_id: str, method: int = 0) -> ProviderAuthAuthorization:
"""Start auth flow for a provider."""
return await self.get_backend(provider_id).authorize(method)
|
callback
async
callback(
provider_id: str,
*,
code: str | None = None,
device_code: str | None = None,
verifier: str | None = None,
) -> bool
Handle auth callback for a provider.
Source code in src/llmling_models/auth/auth_service.py
| async def callback(
self,
provider_id: str,
*,
code: str | None = None,
device_code: str | None = None,
verifier: str | None = None,
) -> bool:
"""Handle auth callback for a provider."""
return await self.get_backend(provider_id).callback(
code=code, device_code=device_code, verifier=verifier
)
|
create_default
classmethod
Create auth service with built-in providers.
Source code in src/llmling_models/auth/auth_service.py
| @classmethod
def create_default(cls) -> Self:
"""Create auth service with built-in providers."""
from llmling_models.auth.github_auth import CopilotAuthBackend
from llmling_models.auth.openai_codex_auth import OpenAICodexAuthBackend
from llmling_models.auth.poe_auth import PoeAuthBackend
from llmling_models.auth.zen_auth import ZenAuthBackend
service = cls()
service.register(CopilotAuthBackend())
service.register(OpenAICodexAuthBackend())
service.register(PoeAuthBackend())
service.register(ZenAuthBackend())
return service
|
get_backend
Get backend by provider ID.
Raises:
| Type |
Description |
KeyError
|
If provider_id is not registered.
|
Source code in src/llmling_models/auth/auth_service.py
| def get_backend(self, provider_id: str) -> ProviderAuthBackend:
"""Get backend by provider ID.
Raises:
KeyError: If provider_id is not registered.
"""
try:
return self._backends[provider_id]
except KeyError:
raise KeyError(f"Unknown provider: {provider_id}") from None
|
methods
Return auth methods for all registered providers.
Source code in src/llmling_models/auth/auth_service.py
| def methods(self) -> dict[str, list[ProviderAuthMethod]]:
"""Return auth methods for all registered providers."""
return {pid: backend.methods() for pid, backend in self._backends.items()}
|
register
Register an auth backend.
Source code in src/llmling_models/auth/auth_service.py
| def register(self, backend: ProviderAuthBackend) -> None:
"""Register an auth backend."""
self._backends[backend.provider_id] = backend
|
remove_credentials
async
remove_credentials(provider_id: str) -> bool
Remove credentials for a provider.
Source code in src/llmling_models/auth/auth_service.py
| async def remove_credentials(self, provider_id: str) -> bool:
"""Remove credentials for a provider."""
return await self.get_backend(provider_id).remove_credentials()
|
set_credentials
async
set_credentials(provider_id: str, info: AuthInfo) -> bool
Set credentials for a provider.
Source code in src/llmling_models/auth/auth_service.py
| async def set_credentials(self, provider_id: str, info: AuthInfo) -> bool:
"""Set credentials for a provider."""
return await self.get_backend(provider_id).set_credentials(info)
|
WellKnownAuthInfo
Bases: BaseModel
Well-known authentication credentials.
Source code in src/llmling_models/auth/models.py
| class WellKnownAuthInfo(BaseModel):
"""Well-known authentication credentials."""
type: Literal["wellknown"]
"""Auth type discriminator."""
key: str
"""Key identifier."""
token: str
"""Authentication token."""
|
type
instance-attribute
type: Literal['wellknown']