Skip to content
Merged
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
26 changes: 25 additions & 1 deletion .sdk.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "aab0ca2e-7260-4554-80ac-b7d0498e9626",
"id": "32008b50-ddc2-4a62-a401-51fd86c63158",
"tracked_paths": [
{
"editable": true,
Expand Down Expand Up @@ -37,6 +37,18 @@
"editable": true,
"path": "magic_hour/resources/v1/account/__init__.py"
},
{
"editable": true,
"path": "magic_hour/resources/v1/account/checkout/README.md"
},
{
"editable": true,
"path": "magic_hour/resources/v1/account/checkout/__init__.py"
},
{
"editable": true,
"path": "magic_hour/resources/v1/account/checkout/client.py"
},
{
"editable": true,
"path": "magic_hour/resources/v1/account/client.py"
Expand Down Expand Up @@ -517,6 +529,10 @@
"editable": true,
"path": "magic_hour/types/models/__init__.py"
},
{
"editable": false,
"path": "magic_hour/types/models/v1_account_checkout_create_response.py"
},
{
"editable": false,
"path": "magic_hour/types/models/v1_account_list_response.py"
Expand Down Expand Up @@ -745,6 +761,10 @@
"editable": true,
"path": "magic_hour/types/params/__init__.py"
},
{
"editable": false,
"path": "magic_hour/types/params/v1_account_checkout_create_body.py"
},
{
"editable": false,
"path": "magic_hour/types/params/v1_ai_clothes_changer_create_body.py"
Expand Down Expand Up @@ -1097,6 +1117,10 @@
"editable": true,
"path": "pyproject.toml"
},
{
"editable": false,
"path": "tests/test_v1_account_checkout_client.py"
},
{
"editable": false,
"path": "tests/test_v1_account_client.py"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ download_urls = result.downloads

- [list](magic_hour/resources/v1/account/README.md#list) - Get account details

### [v1.account.checkout](magic_hour/resources/v1/account/checkout/README.md)

- [create](magic_hour/resources/v1/account/checkout/README.md#create) - Create checkout

### [v1.ai_clothes_changer](magic_hour/resources/v1/ai_clothes_changer/README.md)

- [create](magic_hour/resources/v1/ai_clothes_changer/README.md#create) - AI Clothes Changer
Expand Down
1 change: 1 addition & 0 deletions magic_hour/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Submodules

- [checkout](resources/v1/account/checkout/README.md) - checkout
- [account](resources/v1/account/README.md) - account
- [ai_clothes_changer](resources/v1/ai_clothes_changer/README.md) - ai_clothes_changer
- [ai_face_editor](resources/v1/ai_face_editor/README.md) - ai_face_editor
Expand Down
2 changes: 1 addition & 1 deletion magic_hour/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Environment(enum.Enum):
"""Pre-defined base URLs for the API"""

ENVIRONMENT = "https://api.magichour.ai"
MOCK_SERVER = "https://api.sideko.dev/v1/mock/magichour/magic-hour/0.102.0"
MOCK_SERVER = "https://api.sideko.dev/v1/mock/magichour/magic-hour/0.103.0"


def _get_base_url(
Expand Down
4 changes: 4 additions & 0 deletions magic_hour/resources/v1/account/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ res = await client.v1.account.list()
```python
{"credits": 12500, "email": "user@example.com", "id": "cuid-example", "subscription": {"billing_interval": "month", "cancel_at_period_end": False, "current_period_end": "2026-10-01T00:00:00.000Z", "discount": {"amount_off": 123, "percent_off": 20.0}, "name": "Pro", "price": {"amount": 4900, "currency": "usd"}, "status": "active"}, "tier": "pro"}
```

## Submodules

- [checkout](checkout/README.md) - checkout
53 changes: 53 additions & 0 deletions magic_hour/resources/v1/account/checkout/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# v1.account.checkout

## Module Functions

### Create checkout <a name="create"></a>

Create a Stripe Checkout link for the account that owns the API key. Nothing is charged until the checkout is completed in a browser.

**API Endpoint**: `POST /v1/account/checkout`

#### Parameters

| Parameter | Required | Description | Example |
| ------------------ | :------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------- |
| `type_` | ✓ | What to buy. `credit_pack` is a one-time credit purchase. | `"credit_pack"` |
| `credit_shortfall` | ✗ | Credits a blocked request is missing, e.g. `credit_shortfall` from a 402 response. The checkout starts with enough packs to cover it. Defaults to one pack. | `150.0` |
| `pack_count` | ✗ | Number of credit packs the checkout starts with. Takes priority over `credit_shortfall`. | `3` |

#### Synchronous Client

```python
from magic_hour import Client
from os import getenv

client = Client(token=getenv("API_TOKEN"))
res = client.v1.account.checkout.create(
type_="credit_pack", credit_shortfall=150.0, pack_count=3
)
```

#### Asynchronous Client

```python
from magic_hour import AsyncClient
from os import getenv

client = AsyncClient(token=getenv("API_TOKEN"))
res = await client.v1.account.checkout.create(
type_="credit_pack", credit_shortfall=150.0, pack_count=3
)
```

#### Response

##### Type

[V1AccountCheckoutCreateResponse](/magic_hour/types/models/v1_account_checkout_create_response.py)

##### Example

```python
{"checkout_url": "https://pay.magichour.ai/c/pay/cs_live_..."}
```
4 changes: 4 additions & 0 deletions magic_hour/resources/v1/account/checkout/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .client import AsyncCheckoutClient, CheckoutClient


__all__ = ["AsyncCheckoutClient", "CheckoutClient"]
134 changes: 134 additions & 0 deletions magic_hour/resources/v1/account/checkout/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import typing
import typing_extensions

from magic_hour.types import models, params
from make_api_request import (
AsyncBaseClient,
RequestOptions,
SyncBaseClient,
default_request_options,
to_encodable,
type_utils,
)


class CheckoutClient:
def __init__(self, *, base_client: SyncBaseClient):
self._base_client = base_client

def create(
self,
*,
type_: typing_extensions.Literal["credit_pack"],
credit_shortfall: typing.Union[
typing.Optional[float], type_utils.NotGiven
] = type_utils.NOT_GIVEN,
pack_count: typing.Union[
typing.Optional[int], type_utils.NotGiven
] = type_utils.NOT_GIVEN,
request_options: typing.Optional[RequestOptions] = None,
) -> models.V1AccountCheckoutCreateResponse:
"""
Create checkout

Create a Stripe Checkout link for the account that owns the API key. Nothing is charged until the checkout is completed in a browser.

POST /v1/account/checkout

Args:
credit_shortfall: Credits a blocked request is missing, e.g. `credit_shortfall` from a 402 response. The checkout starts with enough packs to cover it. Defaults to one pack.
pack_count: Number of credit packs the checkout starts with. Takes priority over `credit_shortfall`.
type_: What to buy. `credit_pack` is a one-time credit purchase.
request_options: Additional options to customize the HTTP request

Returns:
200

Raises:
ApiError: A custom exception class that provides additional context
for API errors, including the HTTP status code and response body.

Examples:
```py
client.v1.account.checkout.create(
type_="credit_pack", credit_shortfall=150.0, pack_count=3
)
```
"""
_json = to_encodable(
item={
"credit_shortfall": credit_shortfall,
"pack_count": pack_count,
"type_": type_,
},
dump_with=params._SerializerV1AccountCheckoutCreateBody,
)
return self._base_client.request(
method="POST",
path="/v1/account/checkout",
auth_names=["bearerAuth"],
json=_json,
cast_to=models.V1AccountCheckoutCreateResponse,
request_options=request_options or default_request_options(),
)


class AsyncCheckoutClient:
def __init__(self, *, base_client: AsyncBaseClient):
self._base_client = base_client

async def create(
self,
*,
type_: typing_extensions.Literal["credit_pack"],
credit_shortfall: typing.Union[
typing.Optional[float], type_utils.NotGiven
] = type_utils.NOT_GIVEN,
pack_count: typing.Union[
typing.Optional[int], type_utils.NotGiven
] = type_utils.NOT_GIVEN,
request_options: typing.Optional[RequestOptions] = None,
) -> models.V1AccountCheckoutCreateResponse:
"""
Create checkout

Create a Stripe Checkout link for the account that owns the API key. Nothing is charged until the checkout is completed in a browser.

POST /v1/account/checkout

Args:
credit_shortfall: Credits a blocked request is missing, e.g. `credit_shortfall` from a 402 response. The checkout starts with enough packs to cover it. Defaults to one pack.
pack_count: Number of credit packs the checkout starts with. Takes priority over `credit_shortfall`.
type_: What to buy. `credit_pack` is a one-time credit purchase.
request_options: Additional options to customize the HTTP request

Returns:
200

Raises:
ApiError: A custom exception class that provides additional context
for API errors, including the HTTP status code and response body.

Examples:
```py
await client.v1.account.checkout.create(
type_="credit_pack", credit_shortfall=150.0, pack_count=3
)
```
"""
_json = to_encodable(
item={
"credit_shortfall": credit_shortfall,
"pack_count": pack_count,
"type_": type_,
},
dump_with=params._SerializerV1AccountCheckoutCreateBody,
)
return await self._base_client.request(
method="POST",
path="/v1/account/checkout",
auth_names=["bearerAuth"],
json=_json,
cast_to=models.V1AccountCheckoutCreateResponse,
request_options=request_options or default_request_options(),
)
3 changes: 3 additions & 0 deletions magic_hour/resources/v1/account/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import typing

from magic_hour.resources.v1.account.checkout import AsyncCheckoutClient, CheckoutClient
from magic_hour.types import models
from make_api_request import (
AsyncBaseClient,
Expand All @@ -12,6 +13,7 @@
class AccountClient:
def __init__(self, *, base_client: SyncBaseClient):
self._base_client = base_client
self.checkout = CheckoutClient(base_client=self._base_client)

def list(
self, *, request_options: typing.Optional[RequestOptions] = None
Expand Down Expand Up @@ -50,6 +52,7 @@ def list(
class AsyncAccountClient:
def __init__(self, *, base_client: AsyncBaseClient):
self._base_client = base_client
self.checkout = AsyncCheckoutClient(base_client=self._base_client)

async def list(
self, *, request_options: typing.Optional[RequestOptions] = None
Expand Down
Loading
Loading