Skip to content
Socaity Docs

Deploy to Cloud

Intermediate
10 min

Write an APIPod service, build a container image, deploy it to serverless GPU infrastructure, and verify the live endpoint with both curl and the Python SDK.

Prerequisites

You will need the APIPod CLI and the Socaity CLI installed:

terminal
pip install apipod socaity

Log in so both CLIs can access your account:

terminal
# socaity login is the default β€” it authenticates both CLIs.
socaity login

# apipod login is a mirror, kept for convenience.
# apipod login

Step 1 β€” Write the Service

Create service.py. This example wraps FLUX Schnell as a deployable endpoint. Load the model at module level so it is initialised once per container instance, not on every request.

python
# service.py
import os
from socaity import flux_schnell
from apipod import APIPod

app = APIPod()

# Load once per container β€” not on every request
flux = flux_schnell(api_key=os.getenv("SOCAITY_API_KEY"))

@app.endpoint("/generate")
def generate(prompt: str, num_outputs: int = 1, seed: int = None) -> list[str]:
    """Generate images from a text prompt."""
    images = flux(
        prompt=prompt,
        num_outputs=num_outputs,
        seed=seed,
    ).get_result()
    # Return base64-encoded images for transport
    return [img.to_base64() for img in images]

Step 2 β€” Declare Dependencies

List your Python dependencies. APIPod resolves CUDA-compatible wheels automatically.

requirements.txt
socaity>=0.3.0
apipod>=0.2.0
Pillow>=10.0.0

Step 3 β€” Build the Container Image

apipod --build creates a GPU-optimised Docker image. The build runs in the cloud β€” you do not need Docker installed locally.

terminal
apipod --build service.py

Build output:

terminal
β†’ Resolving dependencies...
β†’ Selecting CUDA 12.1 base image
β†’ Installing Python packages (remote build)
β†’ Running health check
βœ“ Image built: service:latest (3.2 GB)
βœ“ Pushed to Socaity registry

Step 4 β€” Deploy Serverless

Push the image and register it as a serverless endpoint. Specify the cloud provider and GPU class. The platform scales to zero between requests β€” you pay only for active GPU-seconds.

terminal
# Live today β€” uses the apipod CLI.
apipod --build --image service:latest

# Coming soon β€” unified socaity CLI will mirror this:
# socaity deploy --image service:latest \
#   --serverless --provider runpod --name flux-service
terminal
βœ“ Endpoint registered
βœ“ Cold-start target: < 8 s
βœ“ Scaling: 0 β†’ 10 replicas
βœ“ Live at: https://api.socaity.ai/endpoints/flux-service/generate

Step 5 β€” Test with curl

Every deployed endpoint accepts standard HTTP POST requests. Test it directly with curl before wiring it into your application.

terminal
curl -X POST https://api.socaity.ai/endpoints/flux-service/generate \
  -H "Authorization: Bearer $SOCAITY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A lighthouse in a storm, oil painting",
    "num_outputs": 1
  }'

Step 6 β€” Call via HTTP

Every deployed APIPod endpoint accepts standard HTTP requests. Use requests or any HTTP client to call your service directly.

python
import os
import requests

endpoint_url = "https://api.socaity.ai/endpoints/flux-service/generate"
headers = {"Authorization": f"Bearer {os.getenv('SOCAITY_API_KEY')}"}

resp = requests.post(
    endpoint_url,
    json={"prompt": "A lighthouse in a storm, oil painting", "num_outputs": 1},
    headers=headers,
)
job = resp.json()   # {"job_id": "...", ...}
print(job)

Supported Cloud Providers

ProviderFlagGPU ClassesNotes
RunPod--provider runpodT4, A10G, A100, H100Default and only wired-in serverless provider today. EU region.
Multi-provider dedicatedβ€”β€”Dedicated hosting across providers is coming soon β€” tracked separately.

Deployment Flags Reference

FlagDefaultDescription
--serverlessfalseScale to zero between requests (recommended for sporadic traffic).
--gpuA10GGPU class to request. Overrides apipod.json if set.
--min-replicas0Minimum always-warm replicas (0 = full serverless).
--max-replicas10Maximum concurrent replicas for autoscaling.
--nameimage tagHuman-readable name for the endpoint in the dashboard.

What You Built

  • Wrote an APIPod service with the @app.endpoint decorator
  • Built a cloud-side GPU container image with apipod --build
  • Deployed serverless to RunPod EU with apipod --build (unified socaity deploy CLI coming soon)
  • Verified the live endpoint with curl and the Python SDK