Code Examples

Ready-to-run examples for common IIO governance patterns

Python curl 1. Basic Chat Completion (OpenAI-compatible)
# Python — drop-in replacement for OpenAI
from openai import OpenAI

client = OpenAI(
    base_url="https://api.iio.space/v1",
    api_key="your-iio-api-key"
)

response = client.chat.completions.create(
    model="qwen2.5:7b",
    messages=[{"role": "user", "content": "Explain HITL gates in 2 sentences"}],
    temperature=0.7
)
print(response.choices[0].message.content)

# curl equivalent:
# curl https://api.iio.space/v1/chat/completions \
#   -H "Authorization: Bearer your-key" \
#   -H "Content-Type: application/json" \
#   -d '{"model":"qwen2.5:7b","messages":[{"role":"user","content":"Hello"}]}'
Python SDK 2. HITL Gate — Block production action until approved
from iio_governance import HITLGate

gate = HITLGate(
    api_url="https://api.iio.space",
    api_key="your-key"
)

# Check if a named gate is approved before proceeding
result = gate.check("gate.production-deploy")

if result.status == "approved":
    deploy_to_production()
elif result.status == "pending":
    print(f"Waiting for approval from {result.approver}")
    print(f"Timeout in {result.timeout_hours}h")
else:
    print("Gate BLOCKED — cannot deploy")
    raise PermissionError("HITL gate not approved")
Python SDK GitHub Actions 3. Policy Check — Run governance checks in CI/CD
# Python
from iio_governance import PolicyCheck

checker = PolicyCheck(api_url="https://api.iio.space")
report = checker.run()

print(f"Passed: {report.passed}/{report.total}")
for failure in report.failures:
    print(f"  FAIL {failure.id}: {failure.detail}")

if not report.ok:
    raise SystemExit(1)

# GitHub Actions equivalent:
# - uses: iio/policy-check@v1
#   with:
#     iio-api-key: ${{ secrets.IIO_API_KEY }}
#     fail-on-policy-violation: true
LangChain 4. LangChain Agent with IIO Governance Tools
from langchain_openai import ChatOpenAI
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate
from iio_governance.langchain import get_iio_tools

# IIO as the LLM backend (EU-hosted, GDPR-compliant)
llm = ChatOpenAI(
    base_url="https://api.iio.space/v1",
    api_key="your-key",
    model="qwen2.5:7b"
)

# Add IIO governance tools to your agent
tools = get_iio_tools(api_url="https://api.iio.space")
# tools = [iio_hitl_gate, iio_policy_check, iio_compliance_check]

prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a governed AI assistant. Always check HITL gates before production actions."),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}")
])

agent = AgentExecutor(
    agent=create_tool_calling_agent(llm, tools, prompt),
    tools=tools,
    verbose=True
)
TypeScript 5. EU AI Act Compliance Check
import { ComplianceCheck } from '@iio/governance';

const compliance = new ComplianceCheck({
  baseUrl: 'https://api.iio.space',
  apiKey: process.env.IIO_API_KEY!
});

// Check EU AI Act status
const euAiAct = await compliance.checkEuAiAct();
console.log(`Classification: ${euAiAct.classification}`); // "Limited Risk"
console.log(`Art.4 AI Literacy: Since 02.02.2025`);

// Full compliance report
const report = await compliance.fullReport();
console.log(`ISO 42001: ${report.iso42001.score}% PASS`);   // 82%
console.log(`GDPR: ${report.gdpr.status}`);                 // Compliant
console.log(`HITL Gates: ${report.hitlGates.active} active`);// 17
SDK Docs · API Reference · Changelog · System Status