Skip to main content
Complete reference for all SDK classes, methods, and functions.

KubiyaClient

The main entry point for interacting with Kubiya platform APIs.

Class: KubiyaClient

from kubiya import KubiyaClient

client = KubiyaClient(
    api_key: str = None,
    base_url: str = "https://api.kubiya.ai",
    timeout: int = 30,
    retry_attempts: int = 3,
    debug: bool = False
)

Parameters

ParameterTypeDefaultDescription
api_keystrNoneKubiya API key. If not provided, reads from KUBIYA_API_KEY env var
base_urlstr"https://api.kubiya.ai"API endpoint URL
timeoutint30Request timeout in seconds
retry_attemptsint3Number of retries for failed requests
debugboolFalseEnable debug logging

Services

The client provides access to these services:
  • client.agents - Agents Service
  • client.workflows - Workflows Service
  • client.integrations - Integrations Service
  • client.secrets - Secrets Service
  • client.knowledge - Knowledge Service

Methods

execute_workflow(workflow_dict, stream=False, runner=None)
Execute a workflow.
result = client.execute_workflow(
    workflow_dict=wf.to_dict(),
    stream=True,
    runner="kubiya-hosted"
)
Parameters:
  • workflow_dict (dict): Workflow definition as dictionary
  • stream (bool): Enable streaming response
  • runner (str, optional): Runner name
Returns: Generator of events (if stream=True) or execution result

Agents Service

client.agents.create(...)

Create a new agent.
agent = client.agents.create(
    name: str,
    description: str = None,
    llm_model: str = "claude-sonnet-4",
    ai_instructions: str = None,
    tools: List[str] = None,
    integrations: List[str] = None,
    environment: Dict[str, str] = None
)
Returns: Agent object with uuid, name, and other properties

client.agents.list(limit=10, offset=0, filter_term=None)

List agents. Returns: List of agent objects

client.agents.get(agent_uuid)

Get agent details. Returns: Agent object

client.agents.edit(agent_uuid, **kwargs)

Update agent configuration.

client.agents.delete(agent_uuid)

Delete an agent.

Access Control

  • client.agents.access.show(agent_uuid)
  • client.agents.access.add_user(agent_uuid, users: List[str])
  • client.agents.access.add_group(agent_uuid, groups: List[str])
  • client.agents.access.remove_user(agent_uuid, users: List[str])
  • client.agents.access.clear(agent_uuid)

Environment Variables

  • client.agents.env.list(agent_uuid)
  • client.agents.env.set(agent_uuid, env_vars: Dict[str, str])
  • client.agents.env.unset(agent_uuid, var_names: List[str])

AI Instructions

  • client.agents.prompt.get(agent_uuid)
  • client.agents.prompt.set(agent_uuid, instructions: str)

Workflows Service

client.workflows.execute(...)

Execute a workflow.
for event in client.workflows.execute(
    workflow_definition: Union[dict, str],
    parameters: Dict[str, Any] = None,
    runner: str = None,
    stream: bool = True
):
    print(event)
Parameters:
  • workflow_definition: Workflow as dict or JSON string
  • parameters: Parameters to pass to workflow
  • runner: Runner name (optional)
  • stream: Enable streaming

client.workflows.list(filter=None, limit=10, offset=0)

List workflow executions. Returns: List of execution objects

Integrations Service

client.integrations.activate(integration_name)

Activate an integration.
result = client.integrations.activate("github_app")
Returns: Activation result with success and optional install_url

client.integrations.list()

List active integrations.

Secrets Service

client.secrets.create(name, value, description=None)

Create a secret.
client.secrets.create(
    name="api-token",
    value="secret-value",
    description="API token for external service"
)

client.secrets.list()

List secrets (metadata only, not values). Returns: List of secret metadata objects

client.secrets.get(name)

Get secret metadata.

client.secrets.value(name)

Get secret value. Returns: The secret value as string

client.secrets.update(name, value=None, description=None)

Update a secret.

client.secrets.delete(name)

Delete a secret.

Knowledge Service

client.knowledge.query(prompt, stream=False)

Query the knowledge base.
# Simple query
response = client.knowledge.query("How do I deploy to Kubernetes?")

# Streaming query
for event in client.knowledge.query("Container security best practices", stream=True):
    print(event)
Parameters:
  • prompt (str): The query prompt
  • stream (bool): Enable streaming

Workflow DSL

workflow(name)

Create a workflow.
from kubiya.dsl import workflow

wf = workflow("workflow-name")

Workflow Methods

MethodDescription
.description(text)Set workflow description
.params(**kwargs)Define workflow parameters
.step(name, command)Add a simple step
.step(name, callback=fn)Add a step with advanced configuration
.runner(name)Set the workflow runner
.to_dict()Convert to dictionary
.to_json(indent=None)Convert to JSON string
.to_yaml()Convert to YAML string

Step Configuration

Step Callback Methods

MethodDescription
.shell(command)Execute shell command
.python(code)Execute Python code
.docker(image, content)Run in Docker container
.kubiya(url, method, body=None)Call Kubiya API
.tool_def(...)Define custom tool
.depends(step_name)Add dependency on another step
.output(var_name)Capture step output
.condition(expression)Add conditional execution
.description(text)Set step description
.shell_type(type)Set shell type (bash, sh, etc.)
.script(content)Set script content
.args(**kwargs)Set script arguments

Examples

# Simple step
wf.step("hello", "echo 'Hello'")

# Advanced step
wf.step("deploy", callback=lambda s:
    s.shell("kubectl apply -f deployment.yaml")
        .description("Deploy to Kubernetes")
        .depends("build")
        .output("DEPLOYMENT_STATUS")
)

# Python step
wf.step("process", callback=lambda s:
    s.python("print('Processing data...')")
)

# Docker step
wf.step("containerized", callback=lambda s:
    s.docker(
        image="python:3.11",
        content="#!/usr/bin/env python3\nprint('In container')"
    )
)

Async Client

StreamingKubiyaClient

Async version of the client for non-blocking operations.
from kubiya import StreamingKubiyaClient
import asyncio

async def main():
    async with StreamingKubiyaClient(api_key="your-key") as client:
        async for event in client.execute_workflow_stream(workflow_dict):
            print(event)

asyncio.run(main())

Exceptions

kubiya.kubiya_services.exceptions

AgentError

Raised when agent operations fail.
from kubiya.kubiya_services.exceptions import AgentError

try:
    agent = client.agents.get("invalid-uuid")
except AgentError as e:
    print(f"Agent operation failed: {e}")

WorkflowExecutionError

Raised when workflow execution fails.
from kubiya.kubiya_services.exceptions import WorkflowExecutionError

try:
    result = client.workflows.execute(workflow_def, params)
except WorkflowExecutionError as e:
    print(f"Workflow failed: {e}")
    print(f"Failed at step: {e.details.get('step')}")

IntegrationError

Raised when integration operations fail.

IntegrationNotFoundError

Raised when integration is not found or already exists.

SecretError

Raised when secret operations fail.

SecretValidationError

Raised when secret validation fails.

KnowledgeError

Raised when knowledge service operations fail.

Type Hints

The SDK provides type hints for better IDE support:
from typing import Dict, List, Optional, Union, Any
from kubiya import KubiyaClient

def create_agent(client: KubiyaClient, name: str) -> Dict[str, Any]:
    """Create an agent with proper type hints"""
    agent: Dict[str, Any] = client.agents.create(
        name=name,
        description="Agent description",
        llm_model="claude-sonnet-4"
    )
    return agent

Environment Variables

VariableDescriptionDefault
KUBIYA_API_KEYAPI key for authenticationNone
KUBIYA_BASE_URLAPI base URLhttps://api.kubiya.ai

Constants

LLM Models

Available LLM models for agents:
  • "claude-sonnet-4" (recommended)
  • "claude-opus-4"
  • "claude-haiku-4"

Runners

  • "kubiya-hosted" - Default Kubiya-hosted runner
  • Custom runners created via the platform

Next Steps