Runware / sdk-python

The Python Runware SDK is used to run image inference with the Runware API, powered by the RunWare inference platform.
Other
9 stars 6 forks source link

No error is received when making requests with an API Key with insufficient credits or a non-existent API key. #33

Open adilentiq opened 1 month ago

adilentiq commented 1 month ago

Description

No error is received when making any request (e.g imageInference) with a non-existent API key or with an API key having insufficient credits.

Context

OS: Windows Python version: Python 3.12.5 SDK version: runware==0.2.7

Requirements

Reproduction steps

  1. Create a directory

  2. Create a file e.g my_script.py with the following content:

    
    from runware import Runware, IImageInference
    import asyncio
    import os
    from dotenv import load_dotenv

load_dotenv(override=True)

async def main() -> None: runware = Runware( api_key=os.getenv("RUNWARE_API_KEY"), url=os.getenv("RUNWARE_WSS_URL"), log_level='DEBUG' )

await runware.connect()

request_image = IImageInference(
    positivePrompt="cute dog",
    negativePrompt="cloudy, rainy",
    model=os.getenv("RUNWARE_MODEL"),
    lora= [],
    numberResults=1,
    height=512,
    width=512,
)

print(f"Payload: {request_image}")

images = await runware.imageInference(requestImage=request_image)

print(f"Images: {images}")

asyncio.run(main())


3. Create a virtual environment
  ```bash
  python -m venv venv
  1. Activate venv environment

    # Windows
    venv\Scripts\activate
    
    # Linux/MacOS
    source venv/bin/activate
  2. Create a requirements.txt file with the following content:

    aiofiles==23.2.1
    asyncio==3.4.3
    python-dotenv==1.0.1
    runware==0.2.7
    websockets==12.0
  3. Install project dependencies:

 pip install -r requirements.txt
  1. Create .env file and set up environment variables

    touch .env

    Example

    RUNWARE_API_KEY="non_existent_api_key_here"
    RUNWARE_WSS_URL="wss://ws-api.runware.ai/v1"
    RUNWARE_MODEL="civitai:81458@132760"
    1. Run the python script
      python my_script.py

Actual result

Logs for scenario when using an API key with insufficient credits.

...
2024-10-02 19:33:57,953 - runware.server - INFO - Starting heartbeat task
2024-10-02 19:33:57,954 - runware.server - DEBUG - Starting message handler task <Task pending name='Task_Message_Handler' coro=<RunwareServer._handle_messages() running at C:\Users\andre\playground\venv\Lib\site-packages\runware\server.py:180>>
2024-10-02 19:33:57,955 - runware.server - DEBUG - Sending ping
2024-10-02 19:33:57,955 - runware.server - DEBUG - Sending message: [{'taskType': 'ping', 'ping': True}]
2024-10-02 19:33:57,956 - websockets.client - DEBUG - > TEXT '[{"taskType": "ping", "ping": true}]' [36 bytes]
2024-10-02 19:33:57,994 - runware.base - DEBUG - Check # Global images: []
2024-10-02 19:33:58,014 - websockets.client - DEBUG - < TEXT '{"data":[{"taskType":"authentication","connecti...7-8bd2-3c97f6309248"}]}' [103 bytes]
2024-10-02 19:33:58,015 - websockets.client - DEBUG - < TEXT '{\n    "errors": [\n        {\n            "cod...n"\n        }\n    ]\n}' [325 bytes] 
2024-10-02 19:33:58,015 - runware.base - DEBUG - Images check message: {'data': [{'taskType': 'authentication', 'connectionSessionUUID': 'c93290cf-94ec-4c77-8bd2-3c97f6309248'}]}
2024-10-02 19:33:58,016 - runware.base - DEBUG - Images check message: {'errors': [{'code': 'insufficientCredits', 'message': 'Insufficient credits, please add your credit card and top-up you balance at https://my.runware.ai/wallet', 'parameter': 'apiKey', 'type': 'string', 'taskType': 'authentication'}]}
2024-10-02 19:33:58,017 - websockets.client - DEBUG - ! failing connection with code 1006
2024-10-02 19:33:58,018 - websockets.client - DEBUG - = connection is CLOSED
2024-10-02 19:33:58,019 - runware.server - ERROR - Connection Closed Error: no close frame received or sent
2024-10-02 19:33:58,019 - runware.server - DEBUG - Handling close
2024-10-02 19:33:58,020 - runware.server - DEBUG - Cancelling Task_Message_Handler <Task pending name='Task_Message_Handler' coro=<RunwareServer._handle_messages() running at C:\Users\andre\playground\venv\Lib\site-packages\runware\server.py:191>>
2024-10-02 19:33:58,020 - runware.server - DEBUG - Cancelling Task_Heartbeat <Task pending name='Task_Heartbeat' coro=<RunwareServer.heartBeat() running at C:\Users\andre\playground\venv\Lib\site-packages\runware\server.py:300> wait_for=<Future pending cb=[Task.task_wakeup()]>>
2024-10-02 19:33:58,021 - runware.server - INFO - Reconnecting...
2024-10-02 19:33:58,105 - runware.base - DEBUG - Check # Global images: []
2024-10-02 19:33:58,220 - runware.base - DEBUG - Check # Global images: []
2024-10-02 19:33:58,321 - runware.base - DEBUG - Check # Global images: []
2024-10-02 19:33:58,437 - runware.base - DEBUG - Check # Global images: []
2024-10-02 19:33:58,553 - runware.base - DEBUG - Check # Global images: []
2024-10-02 19:33:58,670 - runware.base - DEBUG - Check # Global images: []
...

Expected result

bghira commented 2 weeks ago

@gorantosicpf i will take this one, since i have a fix already

bghira commented 2 weeks ago

47 will resolve the condition for insufficient credits

nonexistent key remains outstanding issue