{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["admonition"]},"type":"markdown"},"seo":{"title":"HiddenLayer's SDK documentation","siteUrl":"https://docs.hiddenlayer.ai","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"hiddenlayers-sdk-documentation","__idx":0},"children":["HiddenLayer's SDK documentation"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The HiddenLayer platform enhances the developer experience for protecting artificial intelligence (AI) and machine learning (ML) models without needing to write complex code or manage the underlying infrastructure."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The HiddenLayer SDK uses Python to provide a simple and efficient way to interact with the HiddenLayer API. This guide will walk you through how to install and use the HiddenLayer Python SDK to retrieve AI Runtime Security and AI Supply Chain Security information."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This SDK can be used to interact with the following HiddenLayer services:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["AI Supply Chain Security (model scanning)"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["AI Runtime Security — Interactions (LLM input/output analysis)"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["AI Runtime Security for Predictive Models"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["AI Attack Simulation (red team evaluations)"]}]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Active Development"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This project is under active development. The full API surface is documented in the SDK's ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://github.com/hiddenlayerai/hiddenlayer-sdk-python/blob/main/api.md","target":"_blank"},"children":["api.md"]},"."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"before-you-begin","__idx":1},"children":["Before You Begin"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The following are required for using the HiddenLayer Python SDK:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Python 3.9+ (this should include pip)"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["HiddenLayer API key and secret; see ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/docs/products/console/apikey_aisec_platform#create-api-key"},"children":["Create API Key"]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"install-sdk","__idx":2},"children":["Install SDK"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Install the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["hiddenlayer-sdk"]}," package with ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://pypi.org/project/hiddenlayer-sdk/","target":"_blank"},"children":["pip"]},"."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"pip install hiddenlayer-sdk\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The HiddenLayer Python SDK offers functionality to interact with other services, such as HuggingFace, AWS, etc."]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To scan models from HuggingFace, install the necessary HuggingFace dependencies via:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"pip install hiddenlayer-sdk[hf]\n"},"children":[]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To scan models from AWS, install the necessary AWS dependencies via:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"pip install hiddenlayer-sdk[aws]\n"},"children":[]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"usage-overview","__idx":3},"children":["Usage Overview"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The main client exposed by the SDK is ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["hiddenlayer.HiddenLayer"]},", which provides access to all HiddenLayer services exposed via API. An async equivalent (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["AsyncHiddenLayer"]},") is also available with the same interface."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"from hiddenlayer import HiddenLayer\n\nclient = HiddenLayer(\n    # Defaults to \"prod-us\"; use \"prod-eu\" for the EU region.\n    # environment=\"prod-eu\",\n    # Credentials are sourced from the environment by default:\n    #   HIDDENLAYER_CLIENT_ID, HIDDENLAYER_CLIENT_SECRET (OAuth2)\n    #   HIDDENLAYER_TOKEN (bearer token)\n)\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["API methods are grouped by resource on the client, for example:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"client.<resource>.<method>(<parameters>)\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For the full list of resources and methods, see the SDK's ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://github.com/hiddenlayerai/hiddenlayer-sdk-python/blob/main/api.md","target":"_blank"},"children":["api.md"]}," and the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://dev.hiddenlayer.ai/","target":"_blank"},"children":["Developer Portal"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"authentication","__idx":4},"children":["Authentication"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To authenticate to HiddenLayer, generate a client ID and secret from the platform UI. See ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/docs/products/console/apikey_aisec_platform#create-api-key"},"children":["Create API Key"]},"."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The SDK supports two authentication methods:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["OAuth2 client credentials"]}," — set ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["HIDDENLAYER_CLIENT_ID"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["HIDDENLAYER_CLIENT_SECRET"]},", or pass ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client_id"]}," / ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client_secret"]}," directly."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Bearer token"]}," — set ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["HIDDENLAYER_TOKEN"]},", or pass ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["bearer_token"]}," directly."]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"from hiddenlayer import HiddenLayer\n\nclient = HiddenLayer(\n    client_id=\"...\",      # Your HiddenLayer API Client ID\n    client_secret=\"...\",  # Your HiddenLayer API Secret Key\n)\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"data-models","__idx":5},"children":["Data Models"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The HiddenLayer Python SDK uses Pydantic to represent data for APIs, which makes the code more readable and type-safe and easier to work with."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Specific data models are organized under ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["hiddenlayer.types"]},". Each resource exposes its own request and response types — see the SDK's ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://github.com/hiddenlayerai/hiddenlayer-sdk-python/blob/main/api.md","target":"_blank"},"children":["api.md"]}," for the full inventory."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"example-usage","__idx":6},"children":["Example Usage"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The HiddenLayer Python SDK comes with a number of examples demonstrating how to use the library for various common use-cases."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["These examples and more are located in the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["examples"]}," directory of the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://github.com/hiddenlayerai/hiddenlayer-sdk-python","target":"_blank"},"children":["GitHub repository"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"initiate-client","__idx":7},"children":["Initiate Client"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"from hiddenlayer import HiddenLayer\n\nclient = HiddenLayer(\n    # environment=\"prod-eu\",  # default is \"prod-us\"\n    client_id=\"...\",\n    client_secret=\"...\",\n)\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"scanning-models","__idx":8},"children":["Scanning Models"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"scanning-a-model-on-disk","__idx":9},"children":["Scanning a model on disk"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"scan_results = client.model_scanner.scan_file(\n    model_name=\"sdk_example_model\",\n    model_path=\"./models/example_model.xgb\",\n)\n\nprint(scan_results)\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"scanning-a-hugging-face-model","__idx":10},"children":["Scanning a Hugging Face model"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"from hiddenlayer.lib import CommunityScanSource\n\nhuggingface_scan_results = client.community_scanner.community_scan(\n    model_name=\"bert-tiny-torch-vuln\",\n    model_path=\"drhyrum/bert-tiny-torch-vuln\",\n    model_source=CommunityScanSource.HUGGING_FACE,\n)\n\nprint(huggingface_scan_results)\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"runtime-security","__idx":11},"children":["Runtime Security"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"analyzing-llm-interactions","__idx":12},"children":["Analyzing LLM Interactions"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Use ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client.interactions.analyze"]}," to send LLM input and output to the Interactions endpoint. For a full walkthrough and an example response, see ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/docs/products/runtime/interactions"},"children":["Getting Started with Interactions"]},"."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"response = client.interactions.analyze(\n    metadata={\n        \"model\": \"gpt-5\",\n        \"requester_id\": \"user-1234\",\n        \"provider\": \"openai\",\n    },\n    input={\n        \"messages\": [\n            {\"role\": \"user\", \"content\": \"What is the largest moon of Jupiter?\"}\n        ]\n    },\n    output={\n        \"messages\": [\n            {\"role\": \"assistant\", \"content\": \"The largest moon of Jupiter is Ganymede.\"}\n        ]\n    },\n)\nprint(response)\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To target a locally-running Runtime Security container instead of the SaaS endpoint, set ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["base_url=\"http://localhost:8000\""]}," (or your container's URL) when constructing the client."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"submitting-vectors-to-runtime-security-predictive-models","__idx":13},"children":["Submitting vectors to Runtime Security (Predictive Models)"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For Predictive Model runtime use cases, see the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["examples/mldr.py"]}," script in the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://github.com/hiddenlayerai/hiddenlayer-sdk-python","target":"_blank"},"children":["SDK repository"]},"."]}]},"headings":[{"value":"HiddenLayer's SDK documentation","id":"hiddenlayers-sdk-documentation","depth":1},{"value":"Before You Begin","id":"before-you-begin","depth":2},{"value":"Install SDK","id":"install-sdk","depth":2},{"value":"Usage Overview","id":"usage-overview","depth":2},{"value":"Authentication","id":"authentication","depth":2},{"value":"Data Models","id":"data-models","depth":2},{"value":"Example Usage","id":"example-usage","depth":2},{"value":"Initiate Client","id":"initiate-client","depth":3},{"value":"Scanning Models","id":"scanning-models","depth":3},{"value":"Scanning a model on disk","id":"scanning-a-model-on-disk","depth":4},{"value":"Scanning a Hugging Face model","id":"scanning-a-hugging-face-model","depth":4},{"value":"Runtime Security","id":"runtime-security","depth":3},{"value":"Analyzing LLM Interactions","id":"analyzing-llm-interactions","depth":4},{"value":"Submitting vectors to Runtime Security (Predictive Models)","id":"submitting-vectors-to-runtime-security-predictive-models","depth":4}],"frontmatter":{"seo":{"title":"HiddenLayer's SDK documentation"}},"lastModified":"2026-05-08T18:56:43.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/docs/integrations/sdk_python","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}