{"record":{"id":"2cfd09cc9e6b042d","repo":"huggingface/smolagents","slug":"since-api-name-was-not-defined-it-was-automatic","errorCode":null,"errorMessage":"Since `api_name` was not defined, it was automatically set to the first available API: `{api_name}`.","messagePattern":"Since `api_name` was not defined, it was automatically set to the first available API: `(.+?)`\\.","errorType":"console","errorClass":"UserWarning","httpStatus":null,"severity":"info","filePath":"src/smolagents/tools.py","lineNumber":666,"sourceCode":"            def __init__(\n                self,\n                space_id: str,\n                name: str,\n                description: str = \"\",\n                api_name: str | None = None,\n                token: str | None = None,\n            ):\n                self.name = name\n                self.description = description\n                self.client = Client(space_id, hf_token=token)\n                space_api = self.client.view_api(return_format=\"dict\", print_info=False)\n                assert isinstance(space_api, dict)\n                space_description = space_api[\"named_endpoints\"]\n\n                # If api_name is not defined, take the first of the available APIs for this space\n                if api_name is None:\n                    api_name = list(space_description.keys())[0]\n                    warnings.warn(\n                        f\"Since `api_name` was not defined, it was automatically set to the first available API: `{api_name}`.\"\n                    )\n                self.api_name = api_name\n\n                try:\n                    space_description_api = space_description[api_name]\n                except KeyError:\n                    raise KeyError(f\"Could not find specified {api_name=} among available api names.\")\n                self.inputs = {}\n                for parameter in space_description_api[\"parameters\"]:\n                    parameter_type = parameter[\"type\"][\"type\"]\n                    if parameter_type == \"object\":\n                        parameter_type = \"any\"\n                    self.inputs[parameter[\"parameter_name\"]] = {\n                        \"type\": parameter_type,\n                        \"description\": parameter[\"python_type\"][\"description\"],\n                        \"nullable\": parameter[\"parameter_has_default\"],\n                    }","sourceCodeStart":648,"sourceCodeEnd":684,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/tools.py#L648-L684","documentation":"When constructing a Tool from a Hugging Face Space (`Tool.from_space(...)` or the SpaceUrl path) without an `api_name`, smolagents picks the first endpoint listed in the Space's `named_endpoints` and warns about it. The chosen endpoint may not be the one you intend to call. The warning is informational; you should confirm the picked `api_name` matches your expectation.","triggerScenarios":"`Tool.from_space('username/space-name')` (or `Tool(url=...)`) with `api_name=None` while the Space exposes multiple named endpoints. The constructor takes `list(space_description['named_endpoints'].keys())[0]` as the API.","commonSituations":"Wrapping a multi-endpoint Gradio Space (e.g. image-to-image Spaces with extra endpoints like /upscale) and assuming a default route; Spaces that add new endpoints over time, silently changing which one is 'first'.","solutions":["Pass an explicit `api_name`: `Tool.from_space('user/space', api_name='/predict')`","Inspect the Space's endpoints (`https://huggingface.co/spaces/user/space`) to find the correct named endpoint before constructing the tool","If the auto-picked endpoint is actually correct, verify `tool.api_name` after construction and suppress/ignore the warning"],"exampleFix":"# before\ntool = Tool.from_space('black-forest-labs/FLUX.1-schnell')\n\n# after\ntool = Tool.from_space('black-forest-labs/FLUX.1-schnell', api_name='/infer')","handlingStrategy":"validation","validationCode":"from huggingface_hub import get_space_metadata  # or query the space config\nimport requests\n\ndef list_space_endpoints(space_id: str) -> list[str]:\n    r = requests.get(f'https://huggingface.co/spaces/{space_id}/config', timeout=10)\n    return list(r.json().get('named_endpoints', {}).keys())  # pass one as api_name","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass api_name when wrapping a Space with Tool.from_space","After construction, assert tool.api_name equals the endpoint you expect","Re-check endpoints when a Space you depend on is updated"],"tags":["gradio","huggingface-space","tool","smolagents","default-value"],"backgroundTag":"ambiguous-default-endpoint","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}