From 8c9830eef9171966a057806af870aac4a2fa16d2 Mon Sep 17 00:00:00 2001 From: Mateo Wang <277851410+mateo-berri@users.noreply.github.com> Date: Thu, 7 May 2026 09:39:26 -0700 Subject: [PATCH] =?UTF-8?q?feat(xai):=20add=20grok-4.3=20and=20grok-4.3-la?= =?UTF-8?q?test=20to=20model=5Fprices=5Fand=5Fconte=E2=80=A6=20(#27154)=20?= =?UTF-8?q?(#27396)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(xai): add grok-4.3 and grok-4.3-latest to model_prices_and_context_window.json xAI's docs page now lists grok-4.3 as the recommended chat / coding model: "We strongly recommend all API callers use grok-4.3. It is the most intelligent and fastest model we've built." (https://docs.x.ai/docs/models) Pricing/specs sourced from xAI's published model metadata: - input: $1.25 / 1M tokens (<=200k), $2.50 / 1M tokens (>200k) - output: $2.50 / 1M tokens (<=200k), $5.00 / 1M tokens (>200k) - cached: $0.20 / 1M tokens (<=200k), $0.40 / 1M tokens (>200k) - context: 1,000,000 tokens - capabilities: vision, reasoning, function calling, structured outputs, prompt caching, web search Adds two entries: `xai/grok-4.3` (canonical) and `xai/grok-4.3-latest` (alias), mirroring the pattern used for the rest of the xAI/Grok-4 family. * test(xai): add model_info test for grok-4.3 + sync backup cost map - Mirror xai/grok-4.3 and xai/grok-4.3-latest entries into litellm/model_prices_and_context_window_backup.json so the bundled model cost map matches the canonical model_prices_and_context_window.json. - Add tests/test_litellm/test_xai_grok_4_3_model_metadata.py covering pricing tiers, capability flags, context window, provider routing, and parity between the main and backup cost maps. - Point 'source' at the live xAI models page (the per-model URL https://docs.x.ai/docs/models/grok-4.3 currently 404s). --------- Co-authored-by: ishaan-berri <155045088+ishaan-berri@users.noreply.github.com> Co-authored-by: shin-watcher Co-authored-by: Cursor Agent Co-authored-by: Mateo Wang --- ...odel_prices_and_context_window_backup.json | 42 +++++++++++++ model_prices_and_context_window.json | 42 +++++++++++++ .../test_xai_grok_4_3_model_metadata.py | 62 +++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 tests/test_litellm/test_xai_grok_4_3_model_metadata.py diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index 7946e2dcee..1a83df726e 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -34927,6 +34927,48 @@ "supports_vision": true, "supports_web_search": true }, + "xai/grok-4.3": { + "cache_read_input_token_cost": 2e-07, + "cache_read_input_token_cost_above_200k_tokens": 4e-07, + "input_cost_per_token": 1.25e-06, + "input_cost_per_token_above_200k_tokens": 2.5e-06, + "litellm_provider": "xai", + "max_input_tokens": 1000000, + "max_output_tokens": 1000000, + "max_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 2.5e-06, + "output_cost_per_token_above_200k_tokens": 5e-06, + "source": "https://docs.x.ai/docs/models", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": true, + "supports_web_search": true + }, + "xai/grok-4.3-latest": { + "cache_read_input_token_cost": 2e-07, + "cache_read_input_token_cost_above_200k_tokens": 4e-07, + "input_cost_per_token": 1.25e-06, + "input_cost_per_token_above_200k_tokens": 2.5e-06, + "litellm_provider": "xai", + "max_input_tokens": 1000000, + "max_output_tokens": 1000000, + "max_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 2.5e-06, + "output_cost_per_token_above_200k_tokens": 5e-06, + "source": "https://docs.x.ai/docs/models", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": true, + "supports_web_search": true + }, "xai/grok-beta": { "input_cost_per_token": 5e-06, "litellm_provider": "xai", diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index 9c085c2c99..61e7c1de84 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -34932,6 +34932,48 @@ "supports_vision": true, "supports_web_search": true }, + "xai/grok-4.3": { + "cache_read_input_token_cost": 2e-07, + "cache_read_input_token_cost_above_200k_tokens": 4e-07, + "input_cost_per_token": 1.25e-06, + "input_cost_per_token_above_200k_tokens": 2.5e-06, + "litellm_provider": "xai", + "max_input_tokens": 1000000, + "max_output_tokens": 1000000, + "max_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 2.5e-06, + "output_cost_per_token_above_200k_tokens": 5e-06, + "source": "https://docs.x.ai/docs/models", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": true, + "supports_web_search": true + }, + "xai/grok-4.3-latest": { + "cache_read_input_token_cost": 2e-07, + "cache_read_input_token_cost_above_200k_tokens": 4e-07, + "input_cost_per_token": 1.25e-06, + "input_cost_per_token_above_200k_tokens": 2.5e-06, + "litellm_provider": "xai", + "max_input_tokens": 1000000, + "max_output_tokens": 1000000, + "max_tokens": 1000000, + "mode": "chat", + "output_cost_per_token": 2.5e-06, + "output_cost_per_token_above_200k_tokens": 5e-06, + "source": "https://docs.x.ai/docs/models", + "supports_function_calling": true, + "supports_prompt_caching": true, + "supports_reasoning": true, + "supports_response_schema": true, + "supports_tool_choice": true, + "supports_vision": true, + "supports_web_search": true + }, "xai/grok-beta": { "input_cost_per_token": 5e-06, "litellm_provider": "xai", diff --git a/tests/test_litellm/test_xai_grok_4_3_model_metadata.py b/tests/test_litellm/test_xai_grok_4_3_model_metadata.py new file mode 100644 index 0000000000..81e7f4adf1 --- /dev/null +++ b/tests/test_litellm/test_xai_grok_4_3_model_metadata.py @@ -0,0 +1,62 @@ +import json +from pathlib import Path + +import pytest + +from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider + + +@pytest.mark.parametrize("model", ["xai/grok-4.3", "xai/grok-4.3-latest"]) +def test_xai_grok_4_3_model_info(model): + json_path = Path(__file__).parents[2] / "model_prices_and_context_window.json" + with open(json_path) as f: + model_cost = json.load(f) + + info = model_cost.get(model) + assert ( + info is not None + ), f"{model} not found in model_prices_and_context_window.json" + + assert info["litellm_provider"] == "xai" + assert info["mode"] == "chat" + + assert info["input_cost_per_token"] == 1.25e-06 + assert info["output_cost_per_token"] == 2.5e-06 + assert info["cache_read_input_token_cost"] == 2e-07 + + assert info["input_cost_per_token_above_200k_tokens"] == 2.5e-06 + assert info["output_cost_per_token_above_200k_tokens"] == 5e-06 + assert info["cache_read_input_token_cost_above_200k_tokens"] == 4e-07 + + assert info["max_input_tokens"] == 1000000 + assert info["max_output_tokens"] == 1000000 + assert info["max_tokens"] == 1000000 + + assert info["supports_function_calling"] is True + assert info["supports_prompt_caching"] is True + assert info["supports_reasoning"] is True + assert info["supports_response_schema"] is True + assert info["supports_tool_choice"] is True + assert info["supports_vision"] is True + assert info["supports_web_search"] is True + + routed_model, provider, _, _ = get_llm_provider(model=model) + assert routed_model == model.split("/", 1)[1] + assert provider == "xai" + + +def test_xai_grok_4_3_backup_matches_main(): + """Ensure the bundled model cost map stays in sync with the canonical file.""" + repo_root = Path(__file__).parents[2] + main_path = repo_root / "model_prices_and_context_window.json" + backup_path = repo_root / "litellm" / "model_prices_and_context_window_backup.json" + + with open(main_path) as f: + main_cost = json.load(f) + with open(backup_path) as f: + backup_cost = json.load(f) + + for model in ("xai/grok-4.3", "xai/grok-4.3-latest"): + assert backup_cost.get(model) == main_cost.get( + model + ), f"{model} differs between main and backup model cost maps"