Job Classes¶
All job types inherit from BaseCall and provide specialized configurations for different inference tasks.
LLMComplete¶
Single-turn text generation using a prompt.
LLMComplete
dataclass
¶
Bases: BaseCall
LLM Completion job - for text completion, generation, and single-turn tasks.
This class is designed for generation endpoints that accept a single prompt without system context. It's optimized for: - Text completion - Code generation - Creative writing - Single-turn responses - Q&A without conversation context
Note: This does NOT support system messages. Use LLMChat for conversational interactions with system/user/assistant message flows.
Example
job = LLMComplete(model="llama3.3") job.set_prompt("Write a haiku about Python") job.temperature = 0.9
Source code in microdc/jobs/llm_complete.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
set_prompt(prompt)
¶
add_file(file_token)
¶
Add a file token to the completion job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_token
|
str
|
File ID from client.upload_file() response |
required |
add_files(file_tokens)
¶
Add multiple file tokens to the completion job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_tokens
|
List[str]
|
List of file IDs from client.upload_file() responses |
required |
to_api_payload()
¶
Convert to API request format matching JobRequest schema.
Source code in microdc/jobs/llm_complete.py
validate()
¶
Validate LLM completion job configuration.
Source code in microdc/jobs/llm_complete.py
LLMChat¶
Multi-turn conversational AI with system/user/assistant messages.
LLMChat
dataclass
¶
Bases: BaseCall
LLM Chat job - for conversational and multi-turn interactions.
This class supports full message-based interactions with system, user, and assistant roles. It's designed for: - Conversational AI - Multi-turn dialogue - Question answering with context - Assistant-style interactions - Context-aware responses
Example
chat = LLMChat(model="gpt-4") chat.set_system("You are a helpful assistant") chat.add_user_message("What is Python?") chat.add_assistant_message("Python is a programming language") chat.add_user_message("Tell me more")
Source code in microdc/jobs/llm_chat.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
set_system(content)
¶
add_user_message(content)
¶
add_assistant_message(content)
¶
to_api_payload()
¶
Convert to API request format matching JobRequest schema.
Source code in microdc/jobs/llm_chat.py
validate()
¶
Validate LLM chat job configuration.
Source code in microdc/jobs/llm_chat.py
LLMEmbed¶
Text embedding generation for semantic search and RAG.
LLMEmbed
dataclass
¶
Bases: BaseCall
Embedding generation job configuration.
Use this for generating text embeddings for semantic search, similarity, clustering, and other vector-based operations.
Example
job = LLMEmbed(model="text-embedding-ada-002") job.add_texts(["Hello world", "Goodbye world"]) job.normalize = True
Source code in microdc/jobs/embed_call.py
add_text(text)
¶
add_texts(texts)
¶
to_api_payload()
¶
Convert to API request format matching JobRequest schema.
Source code in microdc/jobs/embed_call.py
validate()
¶
Validate embedding job configuration.
Source code in microdc/jobs/embed_call.py
DocumentCall¶
Document processing for file-based analysis workflows.
DocumentCall
dataclass
¶
Bases: BaseCall
Document processing job configuration for file-only processing models.
Document processing models like docling analyze files without requiring text prompts. Files MUST be uploaded before creating the document processing job.
Workflow
- Upload file(s) using client.upload_file()
- Get file token(s) from upload response
- Create DocumentCall with model and file tokens
- Submit job using client.send_job()
Example
Step 1: Upload file¶
upload_result = client.upload_file("document.pdf") file_token = upload_result['id']
Step 2: Create document processing job¶
job = DocumentCall(model="docling") job.add_file(file_token)
Step 3: Submit job¶
job_id = client.send_job(job)
Source code in microdc/jobs/document_call.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
add_file(file_token)
¶
Add a file token to the document processing job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_token
|
str
|
Token from file upload response |
required |
Note
Files must be uploaded using client.upload_file() before adding their tokens to the job.
Source code in microdc/jobs/document_call.py
add_files(file_tokens)
¶
Add multiple file tokens to the document processing job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_tokens
|
List[str]
|
List of tokens from file upload responses |
required |
to_api_payload()
¶
Convert to API request format.
Note: Document processing jobs do NOT include 'input' field in payload. They only process uploaded files referenced by file_ids at the top level.
The API expects file_ids (not file_tokens) at the top level of the request.
Source code in microdc/jobs/document_call.py
validate()
¶
Validate document processing job configuration.
Source code in microdc/jobs/document_call.py
ContainerJob¶
Run an arbitrary Docker container on the platform, with optional GPU, files, environment variables, and resource limits.
ContainerJob
dataclass
¶
Bases: BaseCall
Docker container execution job configuration.
Runs a Docker container on the MicroDC distributed platform. Supports file attachments, GPU access, environment variables, and resource limits.
Workflow
- Create ContainerJob with Docker image
- Optionally set command, environment, resource limits
- Optionally attach files (upload first via client.upload_file())
- Submit job using client.send_job()
Example
Run a Python script in a container¶
job = ContainerJob(image="python:3.11") job.set_command("python /input/script.py") job.add_env_var("API_KEY", "sk-...")
Attach a file (uploaded separately)¶
upload_result = client.upload_file("script.py") job.add_file(upload_result['id'])
job_id = client.send_job(job)
Source code in microdc/jobs/container_job.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
set_image(image)
¶
Set the Docker image to run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
str
|
Docker image name and tag (e.g. "python:3.11", "nvidia/cuda:12.0-runtime") |
required |
set_command(command)
¶
Set the command to run inside the container.
Accepts either shell form (a string) or exec form (a list).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
Union[str, List[str]]
|
Shell command string (e.g. "python /input/script.py") or exec-form list (e.g. ["python", "/input/script.py"]). |
required |
Source code in microdc/jobs/container_job.py
set_entrypoint(entrypoint)
¶
Set the container entrypoint, overriding the image's default.
Pass an empty string to bypass the image's entrypoint entirely
(equivalent to docker run --entrypoint ""). Useful for images
whose default ENTRYPOINT runs init / desktop services that get in
the way of a headless command (e.g. linuxserver.io images).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entrypoint
|
str
|
Entrypoint binary path, or "" to disable. |
required |
Source code in microdc/jobs/container_job.py
set_environment(env)
¶
Replace the environment variables dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env
|
Dict[str, str]
|
Dictionary of environment variable key-value pairs |
required |
add_env_var(key, value)
¶
Add a single environment variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Environment variable name |
required |
value
|
str
|
Environment variable value |
required |
enable_gpu()
¶
set_memory_limit(limit)
¶
Set the container memory limit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
str
|
Memory limit string (e.g. "512m", "4g") |
required |
set_cpu_count(count)
¶
Set the number of CPUs available to the container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
count
|
int
|
Number of CPUs |
required |
add_file(file_token)
¶
Add a file token from a previous upload.
Files must be uploaded using client.upload_file() before adding their tokens to the job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_token
|
str
|
Token from client.upload_file() response |
required |
Source code in microdc/jobs/container_job.py
add_files(file_tokens)
¶
Add multiple file tokens from previous uploads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_tokens
|
List[str]
|
List of tokens from client.upload_file() responses |
required |
set_min_capabilities(capabilities)
¶
Replace the minimum-capability scheduling hints for this job.
These are sent at the top level of the API payload as
min_capabilities and used by the platform to route the job to a
worker that satisfies them (e.g. a GPU with enough VRAM, a specific
GPU model, a memory floor, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
capabilities
|
Dict[str, Any]
|
Dict of capability requirements, e.g.
|
required |
Source code in microdc/jobs/container_job.py
add_min_capability(key, value)
¶
Add or update a single minimum-capability requirement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Capability name (e.g. |
required |
value
|
Any
|
Required value. |
required |
Source code in microdc/jobs/container_job.py
to_api_payload()
¶
Convert to API request format.
The model field is set to the Docker image name for searchability. Container config goes in the "payload" dict, matching other job types.
Source code in microdc/jobs/container_job.py
validate()
¶
Validate container job configuration.
Source code in microdc/jobs/container_job.py
WorkerJob¶
Run a local project folder as a streaming container. Subclass of ContainerJob
that zips a folder containing setup_run.sh, uploads it, and runs it with
internet access enabled.
WorkerJob
dataclass
¶
Bases: ContainerJob
Run a project folder as a container job on the MicroDC platform.
WorkerJob wraps ContainerJob to provide a simple workflow: point it at a
folder containing a setup_run.sh entrypoint and the library handles
zipping, uploading, and configuring the container job.
The folder must contain a setup_run.sh at its root. The worker will
execute this script inside the container with your files mapped in.
Example folder::
my_project/
├── setup_run.sh # Required entrypoint
├── main.py
└── requirements.txt
Usage::
>>> from microdc import Client, WorkerJob
>>> client = Client(api_key="mDC_...")
>>> job = WorkerJob(folder_path="./my_project", image="python:3.11")
>>> job_id = client.send_job(job)
>>> result = client.wait_for_job(job_id)
Works with any language — just pick the right image::
>>> WorkerJob(folder_path="./my_node_app", image="node:20")
>>> WorkerJob(folder_path="./my_go_app", image="golang:1.22")
>>> WorkerJob(folder_path="./my_rust_app", image="rust:1.77")
Attributes:
| Name | Type | Description |
|---|---|---|
folder_path |
str
|
Path to the project folder to run. |
image |
str
|
Docker image (required, e.g. "python:3.11", "node:20", "ubuntu:22.04"). |
network_mode |
str
|
Network mode (default: "bridge" for internet access). |
Source code in microdc/jobs/worker_job.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
validate()
¶
Validate worker job configuration.
Source code in microdc/jobs/worker_job.py
prepare()
¶
Zip the folder contents into a temporary file.
Returns:
| Type | Description |
|---|---|
str
|
Path to the created zip file. |
Source code in microdc/jobs/worker_job.py
BaseCall¶
Abstract base class for all job types.
BaseCall
dataclass
¶
Bases: ABC
Base class for all MicroDC job types.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
str
|
Job type identifier (set by subclasses) |
metadata |
Dict[str, Any]
|
User-defined metadata for tracking |
priority |
Union[int, str]
|
Job priority as int in range 0..100 (higher = scheduled first). Use PRIORITY_LOW (5), PRIORITY_DEFAULT (10), or PRIORITY_HIGH (20). Legacy string aliases ("low", "standard", "high") are accepted and normalized to ints at submission time. |
timeout |
Optional[int]
|
Maximum execution time in seconds |
callback_url |
Optional[str]
|
Optional webhook URL for notifications |
Source code in microdc/jobs/base.py
to_api_payload()
abstractmethod
¶
Convert job to API request payload.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict containing API-compatible job specification |
validate()
abstractmethod
¶
Validate job configuration before submission.
Raises:
| Type | Description |
|---|---|
ValidationError
|
If configuration is invalid |
JobDetails¶
Data class containing job status and results.
JobDetails
dataclass
¶
Complete job information including status and results. Maps to JobResponse schema from the API.
Attributes:
| Name | Type | Description |
|---|---|---|
job_id |
str
|
Unique job identifier (UUID) |
type |
str
|
Job type (LLM, EMBED, etc.) |
status |
str
|
Current status (queued, processing, completed, failed, cancelled) |
model |
str
|
Model used for inference |
created_at |
datetime
|
Job creation timestamp |
started_at |
Optional[datetime]
|
Job start timestamp (if started) |
completed_at |
Optional[datetime]
|
Job completion timestamp (if completed) |
estimated_cost |
Optional[float]
|
Estimated cost in credits |
actual_cost |
Optional[float]
|
Actual cost in credits (if completed) |
result |
Optional[Any]
|
Job results (if completed) |
error_message |
Optional[str]
|
Error message (if failed) |
metadata |
Optional[Dict[str, Any]]
|
User-defined metadata |
priority |
int
|
Job priority as int (0..100, higher = scheduled first) |
retry_count |
int
|
Number of times job has been retried |
user_id |
Optional[str]
|
User ID who submitted the job |