'gpt-5.6-terra', 'gemini' => 'gemini-3.6-flash', 'claude' => 'claude-sonnet-5-5', 'openrouter' => 'openrouter/free', ); /** * Model IDs verified against the provider catalogs and the fresh pricing * snapshot on 2026-09-07. Snapshot aliases are intentionally omitted where * their stable alias is already present. * * `o3` was removed (OpenAI deprecates it 2026-10-23); `gpt-6-astra` added * as the new flagship. `gemini-3.7-flash`/`gemini-3.8-flash` GA'd and were * added; `gemini-3-flash-preview` was removed (superseded, preview-only). * `gemma-3-27b-it` was replaced with `gemma-4-31b-it`, now GA directly on * the Gemini API. `claude-fable-5-1` and `claude-haiku-4-5` were added * (the catalog previously had no Haiku-tier Claude option at all). * `claude-sonnet-5-5`, `claude-opus-5-5` and `claude-haiku-5-5` GA'd and * were added as the new Claude flagship generation; `claude-sonnet-5-5` * is now the Claude default. Every prior Claude id listed below remains * live and is kept for existing stored choices. * * @var array> */ private const MODELS = array( 'openai' => array( 'gpt-6-astra', 'gpt-5.6-sol', 'gpt-5.6-terra', 'gpt-5.6-luna', 'gpt-5.6', 'gpt-5.5', 'gpt-5.4', 'gpt-5.4-mini', 'gpt-5.4-nano', 'gpt-5.2', 'gpt-5.1', 'gpt-5', 'gpt-5-mini', 'gpt-5-nano', 'gpt-4.1', 'gpt-4.1-mini', 'gpt-4o', 'gpt-4o-mini', ), 'gemini' => array( 'gemini-3.8-flash', 'gemini-3.7-flash', 'gemini-3.6-flash', 'gemini-3.5-flash', 'gemini-3.5-flash-lite', 'gemini-3.1-pro-preview', 'gemini-3.1-flash-lite', 'gemini-pro-latest', 'gemini-flash-latest', 'gemini-flash-lite-latest', 'gemma-4-31b-it', ), 'claude' => array( 'claude-sonnet-5-5', 'claude-opus-5-5', 'claude-haiku-5-5', 'claude-sonnet-5', 'claude-opus-5', 'claude-fable-5-1', 'claude-fable-5', 'claude-opus-4-8', 'claude-opus-4-7', 'claude-opus-4-6', 'claude-sonnet-4-6', 'claude-opus-4-5', 'claude-haiku-4-5', ), ); /** * OpenRouter accepts custom model routes, so a syntactically valid route is * normally allowed through for remote catalog validation. These routes were * intentionally removed from the bundled picker and must not survive as * legacy saved defaults. * * @var array */ private const RETIRED_OPENROUTER_MODELS = array( 'meta-llama/llama-3.3-70b-instruct:free', 'deepseek/deepseek-v4-flash:free', 'openai/gpt-oss-120b:free', 'qwen/qwen3-coder:free', 'x-ai/grok-4.1-fast', ); /** * Claude models that answer a forced tool call (tool_choice "tool" or * "any") with HTTP 400 and accept a JSON schema through * output_config.format instead (verified against the live API on * 2026-10-22). * * @var array */ private const CLAUDE_JSON_SCHEMA_MODELS = array( 'claude-sonnet-5-5', 'claude-opus-5-5', 'claude-fable-5-1', ); /** * How each Claude model that thinks on its own turns thinking off for * content generation, in the form the live API accepted on 2026-10-22: * 'disabled' and 'between_tools' are the thinking.type that means "off" * for that model; 'low_effort' (adaptive thinking at output_config.effort * low) is the least thinking a model that cannot turn it off allows. * A model missing here only thinks when asked to. * * @var array */ private const CLAUDE_THINKING_OFF = array( 'claude-sonnet-5-5' => 'between_tools', 'claude-opus-5-5' => 'low_effort', 'claude-haiku-5-5' => 'disabled', 'claude-sonnet-5' => 'disabled', 'claude-opus-5' => 'disabled', 'claude-fable-5-1' => 'low_effort', 'claude-fable-5' => 'low_effort', 'claude-opus-4-8' => 'disabled', 'claude-opus-4-7' => 'disabled', ); /** * @param string $provider AIPT provider ID. * @return array */ public static function get_models( string $provider ): array { return self::MODELS[ $provider ] ?? array(); } /** * @return array Provider ids the catalog has a default for, in catalog order. */ public static function get_providers(): array { return array_keys( self::DEFAULT_MODELS ); } public static function get_default_model( string $provider ): string { return self::DEFAULT_MODELS[ $provider ] ?? self::DEFAULT_MODELS['openai']; } /** * @param string $provider AIPT provider ID. * @param string $model Model ID. * @return bool */ public static function is_supported( string $provider, string $model ): bool { return in_array( $model, self::get_models( $provider ), true ); } /** * Whether a model ID is an acceptable choice for the provider: catalog * membership or a stored custom model ({@see CustomModelStore}) for a * direct provider, or a syntactically valid, non-retired route for * OpenRouter. Empty/whitespace-only input is never a valid choice - it * means "no model specified", which callers resolve to the provider * default themselves rather than treating '' as a choice. * * This is the single source of truth for "is this model acceptable", * shared by {@see normalize_model()}'s silent fallback for already-stored * values and by callers that must reject a new, unsupported choice * outright instead of silently swapping it. * * @param string $provider AIPT provider ID. * @param string|null $model Submitted model ID. * @return bool */ public static function is_valid_model_choice( string $provider, ?string $model ): bool { $model = is_string( $model ) ? trim( $model ) : ''; if ( '' === $model ) { return false; } if ( 'openrouter' === $provider ) { return ! in_array( $model, self::RETIRED_OPENROUTER_MODELS, true ) && 1 === preg_match( '/^[A-Za-z0-9][A-Za-z0-9._-]*\/[A-Za-z0-9][A-Za-z0-9._:-]*$/', $model ); } return self::is_supported( $provider, $model ) || self::is_custom_model( $provider, $model ); } /** * Whether a model ID is one the site owner added to the custom model store * for a direct provider and the catalog does not list. A catalog hit never * reaches the store: the catalog wins, and a catalog id costs no option read. * * @param string $provider AIPT provider ID. * @param string $model Model ID. * @return bool */ public static function is_custom_model( string $provider, string $model ): bool { return null !== self::get_custom_model( $provider, $model ); } /** * The stored entry of a custom model, or null for a catalog id, an id that * is not stored and every OpenRouter route. * * @param string $provider AIPT provider ID. * @param string $model Model ID. * @return array|null See {@see CustomModelStore} for the entry shape. */ public static function get_custom_model( string $provider, string $model ): ?array { if ( ! in_array( $provider, CustomModelStore::PROVIDERS, true ) || '' === $model || self::is_supported( $provider, $model ) ) { return null; } return CustomModelStore::find( $provider, $model ); } /** * Resolve a saved model ID to a currently valid provider model. * * Direct providers are constrained to this catalog and the custom model * store. OpenRouter keeps custom routes for remote validation, except * routes deliberately retired from the bundled catalog so existing saved * settings migrate safely. * * @param string $provider AIPT provider ID. * @param string|null $model Saved model ID. * @return string A usable model ID for the provider. */ public static function normalize_model( string $provider, ?string $model ): string { $model = is_string( $model ) ? trim( $model ) : ''; return self::is_valid_model_choice( $provider, $model ) ? $model : self::get_default_model( $provider ); } /** * GPT-5 and o-series models use modern reasoning request semantics. The * plugin must not send legacy sampling parameters to these models. * * @param string $model OpenAI model ID. * @return bool */ public static function uses_legacy_openai_parameters( string $model ): bool { return 0 === strpos( $model, 'gpt-4' ); } /** * @return array */ public static function get_capabilities( string $provider, string $model ): array { $custom = null; if ( ! self::is_supported( $provider, $model ) ) { $custom = self::get_custom_model( $provider, $model ); if ( null === $custom ) { return array(); } } if ( 'openai' === $provider ) { $legacy = self::uses_legacy_openai_parameters( $model ); return array( 'max_token_parameter' => $legacy ? 'max_tokens' : 'max_completion_tokens', 'supports_temperature' => $legacy, 'supports_top_p' => $legacy, 'supports_frequency_penalty'=> $legacy, 'supports_presence_penalty' => $legacy, 'structured_output' => ( null === $custom || 'json_schema' === $custom['caps']['structured_output'] ) ? 'json_schema' : null, 'vision' => null === $custom ? true : $custom['caps']['vision'], ); } if ( 'gemini' === $provider ) { if ( 0 === strpos( $model, 'gemma-' ) ) { return array( 'max_token_parameter' => 'maxOutputTokens', 'supports_temperature' => true, 'supports_top_p' => true, 'supports_top_k' => true, 'structured_output' => null, 'vision' => null === $custom ? true : $custom['caps']['vision'], ); } return array( 'max_token_parameter' => 'maxOutputTokens', 'supports_temperature' => false, 'supports_top_p' => false, 'supports_top_k' => false, 'structured_output' => ( null === $custom || 'json_schema' === $custom['caps']['structured_output'] ) ? 'response_schema' : null, 'vision' => null === $custom ? true : $custom['caps']['vision'], ); } if ( 'claude' === $provider ) { return array( 'max_token_parameter' => 'max_tokens', 'supports_temperature' => in_array( $model, array( 'claude-opus-4-6', 'claude-sonnet-4-6', 'claude-opus-4-5', 'claude-haiku-4-5' ), true ), 'structured_output' => null === $custom ? ( in_array( $model, self::CLAUDE_JSON_SCHEMA_MODELS, true ) ? 'json_schema' : 'tool_use' ) : ( 'json_schema' === $custom['caps']['structured_output'] ? 'json_schema' : null ), 'thinking_off' => null === $custom ? ( self::CLAUDE_THINKING_OFF[ $model ] ?? null ) : $custom['caps']['thinking_off'], 'vision' => null === $custom ? true : $custom['caps']['vision'], ); } return array(); } }