News for hackers. Stuff that matters.
Re:Hypermode Model Router Preview – OpenRouter Alternative by threeducks on Thursday May 08, 2025 @01:24PM (#43928681)
The Python API example looks like it has been written by an LLM. You don't need to import json, you don't need to set the content type and it is good practice to use context managers ("with" statement) to release the connection in case of exceptions. Also, you don't gain anything by commenting variables with the name of the variable.

The following sample (probably) does the same thing and is almost half as short. I have not tested it because there is no signup (EDIT: I was mistaken, there actually is a "signup" behind the login link, which is Google or GitHub login, so the naming makes sense. I confused it with a previously more prominent waitlist link.)

    import requests

    # Your Hypermode Workspace API key
    api_key = "<YOUR_HYP_WKS_KEY>"

    # Use the Hypermode Model Router API endpoint
    url = f"https://models.hypermode.host/v1/chat/completions"

    headers = {"Authorization": f"Bearer {api_key}"}

    payload = {
        "model": "meta-llama/llama-4-scout-17b-16e-instruct",
        "messages": [
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": "What is Dgraph?"},
        ],
        "max_tokens": 150,
        "temperature": 0.7,
    }

    # Make the API request
    with requests.post(url, headers=headers, json=payload) as response:
        response.raise_for_status()
        print(response.json()["choices"][0]["message"]["content"])
Re:Hypermode Model Router Preview – OpenRouter Alternative by iamtherhino on Thursday May 08, 2025 @01:25PM (#43928704)
Signups are open: hypermode.com/sign-up

There's a waitlist for our prompt to agent product in the banner. That's a good call to update it to be more clear.

Re:Hypermode Model Router Preview – OpenRouter Alternative by threeducks on Thursday May 08, 2025 @01:30PM (#43928753)
Oh, I did not catch that. Sorry!
Re:Hypermode Model Router Preview – OpenRouter Alternative by iamtherhino on Thursday May 08, 2025 @01:32PM (#43928798)
Not at all! I'm updating the banner now
Re:Hypermode Model Router Preview – OpenRouter Alternative by iamtherhino on Thursday May 08, 2025 @04:25PM (#43930938)
updated our python example too!
Re:Hypermode Model Router Preview – OpenRouter Alternative by KTibow on Thursday May 08, 2025 @04:32PM (#43930996)
`post` automatically releases the connection. `with` only makes sense when you use a `requests.Session()`.
Re:Hypermode Model Router Preview – OpenRouter Alternative by threeducks on Monday May 12, 2025 @01:28AM (#43959901)
You are right! https://github.com/psf/requests/blob/c65c780849563c891f35ffc...

The post function calls request the request function which uses its own context manager that will call the close function of the connection object.