> */ public static function all(): array { return [ 'openai' => [ 'name' => 'OpenAI', 'status' => self::AVAILABLE, 'product' => 'OpenAI API (Responses API)', 'hosts' => ['api.openai.com'], 'key_url' => 'https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key', 'key_hint' => 'Create a secret key on the API Keys page of the OpenAI developer platform (the linked OpenAI help article shows where). API usage is billed through the developer platform, separately from a ChatGPT subscription.', 'check' => 'GET https://api.openai.com/v1/models — lists the models your key can use. It does not generate text.', 'chat' => 'Streams answers from https://api.openai.com/v1/responses.', 'model_info' => 'The model list contains IDs only; OpenAI does not report which models support text answers through Responses, so choose a text model.', 'embeddings' => 'Offered by OpenAI. Aiwend has an adapter for it, but semantic search is not switched on in this version.', ], 'anthropic' => [ 'name' => 'Anthropic', 'status' => self::AVAILABLE, 'product' => 'Claude API (Messages API)', 'hosts' => ['api.anthropic.com'], 'key_url' => 'https://platform.claude.com/settings/keys', 'key_hint' => 'Create a key on the API keys page of the Claude Console (keys start with sk-ant-). Keys can be tied to a workspace or not. Aiwend sends no workspace header, so if Check access says the key is not scoped to a workspace, create a new key inside a workspace and use that one. Claude API usage is billed through the Console, separately from a Claude.ai subscription.', 'check' => 'GET https://api.anthropic.com/v1/models — lists the models your key can use. It does not generate text.', 'chat' => 'Streams answers from https://api.anthropic.com/v1/messages.', 'model_info' => 'The model list includes display names, lifecycle and token limits reported by Anthropic. Claude models can think before answering; that thinking counts toward the output limit, is billed as output and is never shown. Where a model allows it, Aiwend asks for a plain answer without up-front thinking.', 'embeddings' => 'Anthropic does not offer its own embedding model, so a Claude connection cannot provide semantic search.', ], 'gemini' => [ 'name' => 'Google Gemini', 'status' => self::AVAILABLE, 'product' => 'Gemini API (Google AI Studio key) — not Vertex AI', 'hosts' => ['generativelanguage.googleapis.com'], 'key_url' => 'https://aistudio.google.com/apikey', 'key_hint' => 'Create a Gemini API key in Google AI Studio. Billing and quota belong to the linked Google Cloud project. Vertex AI credentials are a different product and do not work here.', 'check' => 'GET https://generativelanguage.googleapis.com/v1beta/models — lists the models your key can use. It does not generate text.', 'chat' => 'Streams answers from https://generativelanguage.googleapis.com/v1beta/models/{model}:streamGenerateContent.', 'model_info' => 'The model list reports supported methods, display names and token limits; only models that support generateContent can answer chat. A model in the list can still be refused for your account (for example retired for new users): if answers fail, check Settings > Diagnostics > Recent activity for an HTTP 404 and choose a newer model.', 'embeddings' => 'Offered by Google (embedContent). Not integrated in this version; semantic search is not switched on.', ], 'vertex' => [ 'name' => 'Google Vertex AI', 'status' => self::NOT_IMPLEMENTED, 'product' => 'Vertex AI (Google Cloud project, region and service account)', 'note' => 'Requires additional Google Cloud configuration that this version does not support.', ], 'azure_openai' => [ 'name' => 'Azure OpenAI', 'status' => self::NOT_IMPLEMENTED, 'product' => 'Azure OpenAI (resource endpoint and deployment)', 'note' => 'Requires a resource endpoint and deployment configuration that this version does not support.', ], ]; } /** @return array> */ public static function available(): array { return array_filter(self::all(), static fn(array $p): bool => $p['status'] === self::AVAILABLE); } public static function isAvailable(string $id): bool { return isset(self::available()[$id]); } /** * True when a credential has the unmistakable format of ANOTHER provider (found in live acceptance: an Anthropic key pasted into an OpenAI * connection would be sent to api.openai.com). Only the documented public prefixes are used: Anthropic "sk-ant-", Google "AIza", OpenAI "sk-" * (not "sk-ant-"). Anything else is accepted, so new key formats are never refused. The credential is never echoed or logged. */ public static function looksLikeAnotherProvider(string $provider, string $secret): bool { $s = ltrim($secret); $anthropic = str_starts_with($s, 'sk-ant-'); $google = str_starts_with($s, 'AIza'); $openai = str_starts_with($s, 'sk-') && !$anthropic; return match ($provider) { 'openai' => $anthropic || $google, 'anthropic' => $google || $openai, 'gemini' => $anthropic || $openai, default => false, }; } public static function name(string $id): string { return (string) (self::all()[$id]['name'] ?? $id); } /** * HTTP statuses each provider documents as a refusal BEFORE processing (its error tables list them with no generation and no usage). * Deliberately narrow and provider-specific, not one shared list: a status that a provider does not document this way is treated as * ambiguous for that provider. 402 is on no list (no supported provider documents it). Every 5xx (500, 502, 503, 504, 529), 408, 409 * and status 0 are never listed. All of this is an ASSUMPTION until D7 confirms it with real answers and the provider's usage page. * * @return list */ public static function rejectionStatuses(string $provider): array { return match ($provider) { 'openai' => [400, 401, 403, 404, 422, 429], 'anthropic' => [400, 401, 403, 404, 413, 429], 'gemini' => [400, 403, 404, 429], default => [], }; } /** Model identifiers accepted anywhere a model ID is stored or placed in a request. */ public static function validModelId(string $model): bool { return (bool) preg_match('/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,190}$/D', $model); } }