Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,21 @@ npm/bin/muapi-linux-x86_64
npm/bin/muapi-linux-arm64
npm/bin/muapi-windows-x86_64.exe
.DS_Store
# Local SDK testing files
test_all.py
test_predictions.py
test_req.py
test_sdk.py
test_sdk_videos.py
test_uploads.py

# Local test assets
image.png

# Python cache
__pycache__/
*.pyc

# Virtual environments
venv/
.venv/
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,39 @@ muapi account balance
# Wait for an existing job
muapi predict wait <request_id>
```
## Python SDK

Generate an image:

```python
from muapi import MuAPI

client = MuAPI()

result = client.images.generate(
prompt="A futuristic city at sunset",
model="flux-dev"
)

print(result)

```

Generate a video:

```python
from muapi import MuAPI

client = MuAPI()

result = client.videos.generate(
prompt="A dragon flying through clouds",
model="kling-master",
wait=False
)

print(result)
```
## Commands

### `muapi auth`
Expand Down
11 changes: 11 additions & 0 deletions examples/image_edit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from muapi import MuAPI

client = MuAPI()

result = client.images.edit(
prompt="Convert this image into anime style",
image="https://example.com/image.jpg",
model="flux-kontext-dev"
)

print(result)
10 changes: 10 additions & 0 deletions examples/image_generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from muapi import MuAPI

client = MuAPI()

result = client.images.generate(
prompt="A futuristic city at sunset",
model="flux-dev"
)

print(result)
16 changes: 16 additions & 0 deletions examples/prediction_wait.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from muapi import MuAPI

client = MuAPI()

job = client.videos.generate(
prompt="A cinematic shot of a spaceship",
wait=False
)

request_id = job["request_id"]

result = client.predictions.wait(
request_id
)

print(result)
9 changes: 9 additions & 0 deletions examples/upload_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from muapi import MuAPI

client = MuAPI()

result = client.uploads.upload(
"image.png"
)

print(result)
11 changes: 11 additions & 0 deletions examples/video_generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from muapi import MuAPI

client = MuAPI()

result = client.videos.generate(
prompt="A dragon flying through clouds",
model="kling-master",
wait=False
)

print(result)
2 changes: 2 additions & 0 deletions muapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
__version__ = "0.2.0"

from .sdk import MuAPI
48 changes: 48 additions & 0 deletions muapi/accounts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import httpx

from .config import BASE_URL, get_api_key
from .client import MuapiError


class AccountAPI:
def _headers(self):
key = get_api_key()

if not key:
raise MuapiError(
"No API key configured. Run: muapi auth configure"
)

return {"x-api-key": key}

def balance(self):
resp = httpx.get(
f"{BASE_URL}/account/balance",
headers=self._headers(),
timeout=30.0,
)

if resp.status_code >= 400:
raise MuapiError(resp.text, resp.status_code)

return resp.json()

def topup(
self,
amount: int,
currency: str = "usd",
):
resp = httpx.post(
f"{BASE_URL}/account/topup",
json={
"amount": amount,
"currency": currency.lower(),
},
headers=self._headers(),
timeout=30.0,
)

if resp.status_code >= 400:
raise MuapiError(resp.text, resp.status_code)

return resp.json()
98 changes: 98 additions & 0 deletions muapi/audio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
from . import client


class AudioAPI:
def create(
self,
prompt: str,
title: str = "",
tags: str = "",
instrumental: bool = False,
wait: bool = True,
):
payload = {
"prompt": prompt,
"title": title,
"tags": tags,
"make_instrumental": instrumental,
}

return client.generate(
"suno-create-music",
payload,
wait=wait,
)

def remix(
self,
song_id: str,
prompt: str = "",
title: str = "",
tags: str = "",
wait: bool = True,
):
payload = {
"song_id": song_id,
"prompt": prompt,
"title": title,
"tags": tags,
}

return client.generate(
"suno-remix-music",
payload,
wait=wait,
)

def extend(
self,
song_id: str,
prompt: str = "",
continue_at: float = 0,
wait: bool = True,
):
payload = {
"song_id": song_id,
"prompt": prompt,
"continue_at": continue_at,
}

return client.generate(
"suno-extend-music",
payload,
wait=wait,
)

def from_text(
self,
prompt: str,
duration: float = 10.0,
wait: bool = True,
):
payload = {
"prompt": prompt,
"duration": duration,
}

return client.generate(
"mmaudio-v2/text-to-audio",
payload,
wait=wait,
)

def from_video(
self,
video_url: str,
prompt: str = "",
wait: bool = True,
):
payload = {
"video_url": video_url,
"prompt": prompt,
}

return client.generate(
"mmaudio-v2/video-to-video",
payload,
wait=wait,
)
Loading