Skip to main content

Get started in three steps

Spin up the OpenAI SDK against the LLM7.io endpoint and make your first requests.

Step 1: Set up

pip install openai

Configure the client

You can use LLM7.io without a key for low-volume use. For higher limits, get a free token at token.llm7.io.
import openai

client = openai.OpenAI(
    base_url="https://api.llm7.io/v1",
    api_key="unused",  # or your token from https://token.llm7.io/
)

Step 2: Text generation

Chat completions (Python)

import openai

client = openai.OpenAI(
    base_url="https://api.llm7.io/v1",
    api_key="unused",  # replace if you have a token
)

resp = client.chat.completions.create(
    model="default",
    messages=[
        {"role": "user", "content": "Tell me a short story about a brave squirrel."}
    ],
)

print(resp.choices[0].message.content)
The output will be a short story generated by the model, for example:
Once upon a time, in a lush green forest, there lived a brave squirrel named Sammy. Sammy was known for his adventurous spirit and his willingness to help others. One day, a fierce storm hit the forest, causing a massive tree to fall and block the entrance to the squirrel village. Without hesitation, Sammy gathered his friends and devised a plan to clear the path. With teamwork and determination, they managed to move the fallen tree and restore access to their home. The villagers celebrated Sammy's bravery, and he became a legend in the forest for his courageous act.

Step 3: Image generation

from openai import OpenAI

client = OpenAI(base_url="https://api.llm7.io/v1", api_key="none")

prompt = (
    "A futuristic cityscape at sunset, flying cars, neon reflections, "
    "cinematic cyberpunk, highly detailed"
)

res = client.images.generate(
    model="flux",
    prompt=prompt,
    size="1024x1024",
    extra_body={"seed": 42},
)

print(f"See: {res.data[0].url}")
The output will be a URL to the generated image, for example:
See: https://wsrv.nl/?url=https://api.llm7.io/i/Xr45.jpeg&maxage=31d
Which displays an image like this:A futuristic cityscape at sunset, flying cars, neon reflections, cinematic cyberpunk, highly detailed

Next steps

Need help? Check the API reference above or join the community.