{"record":{"id":"6746480e44ebd98d","repo":"huggingface/smolagents","slug":"received-both-token-and-api-key-arguments-ple","errorCode":null,"errorMessage":"Received both `token` and `api_key` arguments. Please provide only one of them. `api_key` is an alias for `token` to make the API compatible with OpenAI's client. It has the exact same behavior as `token`.","messagePattern":"Received both `token` and `api_key` arguments\\. Please provide only one of them\\. `api_key` is an alias for `token` to make the API compatible with OpenAI's client\\. It has the exact same behavior as `token`\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/smolagents/models.py","lineNumber":1528,"sourceCode":"    \"Quantum mechanics is the branch of physics that studies...\"\n    ```\n    \"\"\"\n\n    def __init__(\n        self,\n        model_id: str = \"Qwen/Qwen3-Next-80B-A3B-Thinking\",\n        provider: str | None = None,\n        token: str | None = None,\n        timeout: int = 120,\n        client_kwargs: dict[str, Any] | None = None,\n        custom_role_conversions: dict[str, str] | None = None,\n        api_key: str | None = None,\n        bill_to: str | None = None,\n        base_url: str | None = None,\n        **kwargs,\n    ):\n        if token is not None and api_key is not None:\n            raise ValueError(\n                \"Received both `token` and `api_key` arguments. Please provide only one of them.\"\n                \" `api_key` is an alias for `token` to make the API compatible with OpenAI's client.\"\n                \" It has the exact same behavior as `token`.\"\n            )\n        token = token if token is not None else api_key\n        if token is None:\n            token = os.getenv(\"HF_TOKEN\")\n        self.client_kwargs = {\n            **(client_kwargs or {}),\n            \"model\": model_id,\n            \"provider\": provider,\n            \"token\": token,\n            \"timeout\": timeout,\n            \"bill_to\": bill_to,\n            \"base_url\": base_url,\n        }\n        super().__init__(model_id=model_id, custom_role_conversions=custom_role_conversions, **kwargs)\n","sourceCodeStart":1510,"sourceCodeEnd":1546,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/models.py#L1510-L1546","documentation":"InferenceClientModel.__init__ accepts both `token` and `api_key` (an OpenAI-compatibility alias for token), but passing both is ambiguous so it raises ValueError immediately. Only one credential argument may be supplied; they are otherwise identical in behavior.","triggerScenarios":"Constructing InferenceClientModel(token=..., api_key=...) in the same call — commonly when code sets api_key explicitly while token is also filled from a config/env wrapper or kwargs merging.","commonSituations":"Migrating OpenAI-style code to smolagents and passing api_key while a framework (e.g. an agent scaffold) injects token; copying examples that use token and adding api_key on top; forwarding **kwargs that happen to contain token.","solutions":["Pass only one of the two: keep `api_key=` for OpenAI-style code, or `token=` — never both.","If a wrapper injects token, remove it from your explicit call (or filter kwargs) so only one credential reaches the constructor."],"exampleFix":"# before\nmodel = InferenceClientModel(model_id=\"...\", token=os.environ[\"HF_TOKEN\"], api_key=os.environ[\"HF_TOKEN\"])\n\n# after\nmodel = InferenceClientModel(model_id=\"...\", api_key=os.environ[\"HF_TOKEN\"])","handlingStrategy":"validation","validationCode":"creds = {k: v for k, v in {\"token\": token, \"api_key\": api_key}.items() if v is not None}\nassert len(creds) <= 1, \"pass only one of token/api_key\"","typeGuard":"null","tryCatchPattern":"try:\n    model = InferenceClientModel(model_id=mid, api_key=key)\nexcept ValueError as e:\n    if \"both `token` and `api_key`\" in str(e):\n        model = InferenceClientModel(model_id=mid, api_key=key)  # retry with single credential\n    else:\n        raise","preventionTips":["Standardize on api_key in OpenAI-style codebases; never forward unfiltered **kwargs that may contain token.","Centralize credential passing in one config helper."],"tags":["huggingface","inference-api","argument-conflict","auth"],"backgroundTag":"duplicate-auth-argument","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}