Package: midjourney-api-client
midjourney-api-clientThis package contains Python client library for Midjourney API byuseapi.net.Useapi.netprovides a simple, reliable and affordable way to useMidjourneyvia standard REST API.Quickdemo.Requirements.Python 3.7+Installation & Usagepip installpipinstallmidjourney-api-clientYou may need to runpipwith root permission:sudo pip install midjourney-api-client.Then import the package:importmidjourney_api_clientAPI OverviewMidjourney/imaginecommand available viajobs/imagineAPI endpoint.Midjourneyupscale or create variationsandenhance or modifybutton commands available viajobs/buttonAPI endpoint.Midjourney/describecommand available viajobs/describeAPI endpoint.Midjourney/blendcommand available viajobs/blendAPI endpoint.Usejobs/?jobid=jobidAPI endpoint to retrieve job results.Postmancollection.Swagger OpenAPIdocumentationfor generating server stubs and client SDKs.UsageYou will need toset up and configurethe Midjourey Discord account as well as subscribe to useapi.net service before you can start using API.Please follow theinstallation procedureand then run the following:importosimporttimefromtypingimportUnionfrompprintimportpprintimportmidjourney_api_clientfrommidjourney_api_client.api.default_apiimportDefaultApifrommidjourney_api_client.models.describe_responseimportDescribeResponsefrommidjourney_api_client.models.imagine_responseimportImagineResponsefrommidjourney_api_client.models.job_responseimportJobResponsefrommidjourney_api_client.models.jobs_blend_post_requestimportJobsBlendPostRequestfrommidjourney_api_client.models.jobs_button_post_requestimportJobsButtonPostRequestfrommidjourney_api_client.models.jobs_describe_post_requestimportJobsDescribePostRequestfrommidjourney_api_client.models.jobs_imagine_post_requestimportJobsImaginePostRequestfrommidjourney_api_client.restimportApiExceptionconfiguration=midjourney_api_client.Configuration(host="https://api.useapi.net/v1")# Extract setting from environment# Suggested shell execution command:# USEAPI_TOKEN="..." USEAPI_DISCORD="..." USEAPI_SERVER="..." USEAPI_CHANNEL="..." python3 ./test.pyapi_token=os.environ["USEAPI_TOKEN"]discord=os.environ["USEAPI_DISCORD"]server=os.environ["USEAPI_SERVER"]channel=os.environ["USEAPI_CHANNEL"]# Optional callback url# We recommend using sites like webhook.site to test callback URL functionality.reply_url=os.environ.get("USEAPI_CALLBACK","")# Configure Bearer authorization: apiTokenconfiguration=midjourney_api_client.Configuration(access_token=api_token)# This function is not not needed if job parameter reply_url (callback) specifieddefwait_for_job_to_complete(api_instance:DefaultApi,job:Union[DescribeResponse,ImagineResponse,JobResponse]):verb=job.verb.upper()print(f"{verb}:{job.status}",job.jobid)whilejob.code==200andjob.statusin['started','progress']:# Sleep for 20 secondstime.sleep(20)job=api_instance.jobs_get(job.jobid)print(f"{verb}:{job.status}",{"jobid":job.jobid,"content":job.content})ifisinstance(job,JobResponse)andjob.attachments:print(f"{verb}url",job.attachments[0].url)ifisinstance(job,JobResponse)andjob.buttons:print(f"{verb}buttons",", ".join(job.buttons))returnjobdefmain():# Enter a context with an instance of the API clientwithmidjourney_api_client.ApiClient(configuration)asapi_client:# Create an instance of the API classapi_instance=midjourney_api_client.DefaultApi(api_client)# Midjourney /describetry:jobs_describe_post_request=JobsDescribePostRequest(describeUrl="https://mymodernmet.com/wp/wp-content/uploads/2017/12/free-images-national-gallery-of-art-9.jpg",discord=discord,server=server,channel=channel,reply_url=reply_url)describe_response=api_instance.jobs_describe_post(jobs_describe_post_request)pprint(describe_response)# Not needed if job parameter reply_url (callback) specifieddescribe_response=wait_for_job_to_complete(api_instance,describe_response)exceptApiExceptionase:print("Exception when calling jobs_describe_post_request:%s\n"%e)# Midjourney /blendtry:jobs_blend_post_request=JobsBlendPostRequest(blendUrls=["https://mymodernmet.com/wp/wp-content/uploads/2017/12/free-images-national-gallery-of-art-6.jpg","https://mymodernmet.com/wp/wp-content/uploads/2017/12/free-images-national-gallery-of-art-2.jpg"],discord=discord,server=server,channel=channel,reply_url=reply_url)blend_response=api_instance.jobs_blend_post(jobs_blend_post_request)pprint(blend_response)# Not needed if job parameter reply_url (callback) specifiedblend_response=wait_for_job_to_complete(api_instance,blend_response)exceptApiExceptionase:print("Exception when calling jobs_blend_post:%s\n"%e)# Midjourney /imaginetry:jobs_imagine_post_request=JobsImaginePostRequest(prompt="Steampunk cat cycling in San Francisco, vintage photo",discord=discord,server=server,channel=channel,reply_url=reply_url)imagine_response=api_instance.jobs_imagine_post(jobs_imagine_post_request)pprint(imagine_response)imagine_response=wait_for_job_to_complete(api_instance,imagine_response)exceptApiExceptionase:print("Exception when calling jobs_imagine_post:%s\n"%e)# Midjourney button commandstry:jobs_button_post_request=JobsButtonPostRequest(button="V1",jobid=imagine_response.jobid,reply_url=reply_url)button_response=api_instance.jobs_button_post(jobs_button_post_request)pprint(button_response)# Not needed if job parameter reply_url (callback) specifiedbutton_response=wait_for_job_to_complete(api_instance,button_response)exceptApiExceptionase:print("Exception when calling jobs_button_post:%s\n"%e)main()Documentation for API EndpointsAll URIs are relative tohttps://api.useapi.net/v1MethodHTTP requestDescriptionjobs_imagine_postPOST/jobs/imagineMidjourney /imagine commandjobs_blend_postPOST/jobs/blendMidjourney /blend commandjobs_describe_postPOST/jobs/describeMidjourney /describe commandjobs_button_postPOST/jobs/buttonMidjourney upscale or create variations and enhance or modify buttonsjobs_getGET/jobs/Retrieve job status and resultsjobs_get_listGET/jobsGet list of currently executing jobsjobs_cancel_getGET/jobs/cancel/Cancel jobaccount_getGET/accountRetrieve useapi.net account informationDocumentation For ModelsAccountResponseBlendResponseButtonResponseButtonResponseErrorUpscaledDescribeResponseImagineResponseImagineResponseModeratedJobCancelResponseJobResponseJobResponseAttachmentsInnerJobResponseChildrenInnerJobResponseEmbedsInnerJobResponseEmbedsInnerImageJobsBlendPostRequestJobsButtonPostRequestJobsDescribePostRequestJobsImaginePostRequestResponseErrorResponseMaxJobsDocumentation For AuthorizationAuthentication schemes defined for the API:apiTokenType: Bearer authenticationChangelogVersion 1.0.1 | November 3, 2023Added support for followingjobs/buttonoptions:Upscale (2x)Upscale (4x)Redo Upscale (2x)Redo Upscale (4x)SupportVisit ourDiscord Serverfor any additional support and questions.YouTube Channelfor tutorials and demos.