{"id":8232,"library":"inference-sdk","title":"Roboflow Inference Python SDK","description":"The Roboflow Inference Python SDK provides a simple interface to deploy and interact with computer vision models from Roboflow. It enables users to perform tasks like object detection, classification, and segmentation locally or via the Roboflow API, abstracting away complex machine learning and deployment details. The current version is 1.2.2, with frequent patch and minor releases.","status":"active","version":"1.2.2","language":"en","source_language":"en","source_url":"https://github.com/roboflow/inference","tags":["computer vision","machine learning","object detection","roboflow","inference","gpu"],"install":[{"cmd":"pip install inference-sdk","lang":"bash","label":"Standard installation (CPU)"},{"cmd":"pip install inference-gpu","lang":"bash","label":"For GPU acceleration (requires pre-installed PyTorch and torchvision with CUDA support)"}],"dependencies":[{"reason":"Required for GPU acceleration with `inference-gpu` package. Specific CUDA version often needs manual pre-installation.","package":"torch","optional":true},{"reason":"Required for GPU acceleration with `inference-gpu` package. Specific CUDA version often needs manual pre-installation.","package":"torchvision","optional":true}],"imports":[{"symbol":"InferenceHTTPClient","correct":"from inference_sdk import InferenceHTTPClient"},{"symbol":"InferenceConfiguration","correct":"from inference_sdk import InferenceConfiguration"}],"quickstart":{"code":"import os\nfrom inference_sdk import InferenceHTTPClient\n\n# Set your Roboflow API Key as an environment variable:\n# export ROBOFLOW_API_KEY=\"YOUR_API_KEY\"\napi_key = os.environ.get('ROBOFLOW_API_KEY', '')\n\nif not api_key:\n    print(\"Warning: ROBOFLOW_API_KEY environment variable not set. Inference might fail.\")\n\n# Initialize the InferenceHTTPClient\n# Use \"https://detect.roboflow.com\" for hosted inference\n# Use \"http://localhost:9001\" if you're running a local inference server\nclient = InferenceHTTPClient(api_url=\"https://detect.roboflow.com\", api_key=api_key)\n\n# Specify your Roboflow model ID (e.g., \"my-project/1\")\n# Replace with a real public model or your own private model ID.\nmodel_id = \"lego-brick-detector/1\" # Example public model\n\n# Define the image source (can be a URL, local path, or base64 string)\nimage_url = \"https://media.roboflow.com/example_input.jpg\"\n\nprint(f\"Attempting inference on {image_url} using model {model_id}...\")\n\ntry:\n    # Perform inference\n    result = client.infer(image_url, model_id=model_id)\n\n    # Print results\n    print(\"Inference successful!\")\n    print(f\"Image dimensions: {result.image.width}x{result.image.height}\")\n    if result.predictions:\n        print(f\"Found {len(result.predictions)} predictions:\")\n        for pred in result.predictions:\n            print(f\"  Class: {pred.class_name}, Confidence: {pred.confidence:.2f}, \"\n                  f\"Box: x={pred.x:.1f}, y={pred.y:.1f}, w={pred.width:.1f}, h={pred.height:.1f}\")\n    else:\n        print(\"No predictions found.\")\n\nexcept Exception as e:\n    print(f\"An error occurred during inference: {e}\")\n    print(\"Please ensure your ROBOFLOW_API_KEY is correct and the model ID is valid.\")","lang":"python","description":"This quickstart demonstrates how to initialize the Inference HTTP client, set your API key (preferably via environment variable), and perform object detection inference on an image from a URL using a specified Roboflow model ID."},"warnings":[{"fix":"Review your application's inference performance and behavior after updating. If issues arise, consult the documentation for opting out of `inference-models` or adapting your model usage.","message":"As of `v1.2.0`, `inference-models` became the default backend for running predictions. While the old backend is available via an opt-out mechanism, this change may affect performance characteristics, model loading behavior, or specific model compatibility.","severity":"breaking","affected_versions":">=1.2.0"},{"fix":"Upgrade your Python environment to 3.10, 3.11, or 3.12 to ensure full compatibility and receive future updates.","message":"Python 3.9 reached End of Life (EOL) and support was officially deprecated in `inference-sdk` `v1.1.0`. While it might still function, future updates may break compatibility.","severity":"deprecated","affected_versions":">=1.1.0"},{"fix":"Install PyTorch and torchvision with CUDA support *before* installing `inference-gpu`. Example: `pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121` (replace `cu121` with your CUDA version), then `pip install inference-gpu`.","message":"For GPU acceleration, installing `inference-gpu` directly without specific PyTorch/torchvision versions can lead to issues. It's recommended to pre-install PyTorch and torchvision with your desired CUDA version first.","severity":"gotcha","affected_versions":"All versions with GPU support"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install PyTorch and torchvision with the correct CUDA version for your system: `pip install torch torchvision --index-url https://download.pytorch.org/whl/cuXX` (replace `cuXX` with your CUDA version, e.g., `cu121`), then `pip install inference-gpu`.","cause":"You are attempting to use the `inference-gpu` package, but PyTorch is not installed or not correctly linked for your environment.","error":"ModuleNotFoundError: No module named 'torch'"},{"fix":"Double-check your `model_id` for typos, ensure your `ROBOFLOW_API_KEY` is correct and has access to the model, and verify that your inference environment meets the model's requirements (e.g., sufficient RAM, GPU memory).","cause":"The specified model_id is incorrect, the model is not accessible (e.g., private model without authentication), or there are environment constraints (e.g., GPU memory limits) that prevent the model from loading on the inference server.","error":"inference_sdk.http.errors.InferenceError: The model failed to load"},{"fix":"Ensure you are accessing results using the documented properties (e.g., `result.predictions`). Consult the official documentation for the response object structure for your `inference-sdk` version. If using an older `inference-sdk` version, upgrade to the latest stable release.","cause":"The inference response object structure might have changed, or your code expects a key that is no longer present, possibly due to a major version update or an error in the inference call itself.","error":"KeyError: 'predictions'"}]}