|
| 1 | +--- |
| 2 | +hidden: true |
| 3 | +noIndex: true |
| 4 | +--- |
| 5 | + |
| 6 | +# qwen-image-edit |
| 7 | + |
| 8 | +{% hint style="info" %} |
| 9 | +This documentation is valid for the following list of our models: |
| 10 | + |
| 11 | +* `alibaba/qwen-image-edit` |
| 12 | +{% endhint %} |
| 13 | + |
| 14 | +## Model Overview |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +## Setup your API Key |
| 19 | + |
| 20 | +If you don’t have an API key for the AI/ML API yet, feel free to use our [Quickstart guide](https://docs.aimlapi.com/quickstart/setting-up). |
| 21 | + |
| 22 | +## API Schema |
| 23 | + |
| 24 | +## Quick Example |
| 25 | + |
| 26 | +Let's generate an image of the specified size using a simple prompt. |
| 27 | + |
| 28 | +{% tabs %} |
| 29 | +{% tab title="Python" %} |
| 30 | +{% code overflow="wrap" %} |
| 31 | +```python |
| 32 | +import requests |
| 33 | +import json |
| 34 | + |
| 35 | + |
| 36 | +def main(): |
| 37 | + response = requests.post( |
| 38 | + "https://api.aimlapi.com/v1/images/generations", |
| 39 | + headers={ |
| 40 | + # Insert your AIML API Key instead of <YOUR_AIMLAPI_KEY>: |
| 41 | + "Authorization": "Bearer <YOUR_AIMLAPI_KEY>", |
| 42 | + "Content-Type": "application/json", |
| 43 | + }, |
| 44 | + json={ |
| 45 | + "model": "alibaba/qwen-image-edit", |
| 46 | + "prompt": "A T-Rex relaxing on a beach, lying on a sun lounger and wearing sunglasses." |
| 47 | + } |
| 48 | + ) |
| 49 | + |
| 50 | + # response.raise_for_status() |
| 51 | + data = response.json() |
| 52 | + |
| 53 | + print(json.dumps(data, indent=2, ensure_ascii=False)) |
| 54 | + |
| 55 | + |
| 56 | +if __name__ == "__main__": |
| 57 | + main() |
| 58 | +``` |
| 59 | +{% endcode %} |
| 60 | +{% endtab %} |
| 61 | + |
| 62 | +{% tab title="JS" %} |
| 63 | +{% code overflow="wrap" %} |
| 64 | +```javascript |
| 65 | +async function main() { |
| 66 | + try { |
| 67 | + const response = await fetch('https://api.aimlapi.com/v1/images/generations', { |
| 68 | + method: 'POST', |
| 69 | + headers: { |
| 70 | + // Insert your AIML API Key instead of <YOUR_AIMLAPI_KEY>: |
| 71 | + 'Authorization': 'Bearer <YOUR_AIMLAPI_KEY>', |
| 72 | + 'Content-Type': 'application/json', |
| 73 | + }, |
| 74 | + body: JSON.stringify({ |
| 75 | + prompt: 'A T-Rex relaxing on a beach, lying on a sun lounger and wearing sunglasses.', |
| 76 | + model: 'alibaba/qwen-image-edit' |
| 77 | + }), |
| 78 | + }); |
| 79 | + |
| 80 | + if (!response.ok) { |
| 81 | + throw new Error(`HTTP error! Status: ${response.status}`); |
| 82 | + } |
| 83 | + |
| 84 | + const data = await response.json(); |
| 85 | + console.log('Generation:', data); |
| 86 | + |
| 87 | + } catch (error) { |
| 88 | + console.error('Error:', error); |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +main(); |
| 93 | +``` |
| 94 | +{% endcode %} |
| 95 | +{% endtab %} |
| 96 | +{% endtabs %} |
| 97 | + |
| 98 | +<details> |
| 99 | + |
| 100 | +<summary>Response</summary> |
| 101 | + |
| 102 | +{% code overflow="wrap" %} |
| 103 | +```json5 |
| 104 | +{ |
| 105 | + "images": [ |
| 106 | + { |
| 107 | + "url": "https://cdn.aimlapi.com/eagle/files/kangaroo/0WBwo2ruHEK9vpmtxu04G.jpeg", |
| 108 | + "width": 1024, |
| 109 | + "height": 768, |
| 110 | + "content_type": "image/jpeg" |
| 111 | + } |
| 112 | + ], |
| 113 | + "timings": { |
| 114 | + "inference": 5.732342581963167 |
| 115 | + }, |
| 116 | + "seed": 4128479875, |
| 117 | + "has_nsfw_concepts": [ |
| 118 | + false |
| 119 | + ], |
| 120 | + "prompt": "A T-Rex relaxing on a beach, lying on a sun lounger and wearing sunglasses." |
| 121 | +} |
| 122 | +``` |
| 123 | +{% endcode %} |
| 124 | + |
| 125 | +</details> |
| 126 | + |
| 127 | +We obtained the following 1024x768 image by running this code example: |
| 128 | + |
| 129 | +<figure><img src="../../../.gitbook/assets/qwen-image.jpeg" alt=""><figcaption><p><code>'A T-Rex relaxing on a beach, lying on a sun lounger and wearing sunglasses.'</code></p></figcaption></figure> |
0 commit comments