Point the OpenAI Python SDK at Refuseless

    All guides

    You switch the OpenAI Python SDK to Refuseless by passing base_url="https://api.refuseless.com/v1" when you construct the client, and by sending a Refuseless model id. The rest of chat.completions.create stays the shape you already have. The key is a Refuseless API key from the console, not an OpenAI key. The SDK will happily send an OpenAI key to the wrong host, and you will get a 401.

    How do you point the Python SDK at Refuseless?

    Install the official SDK (pip install openai) if the project does not have it. Export REFUSELESS_API_KEY. Then construct the client with the base URL. The sample uses glm-5.3-abliterated, the id for GLM 5.3 Abliterated. Use glm-5.3-flash-abliterated for the cheaper Flash model. GET /v1/models returns the ids the key can call.

    Switching the OpenAI SDK to RefuselessYour app keeps using the OpenAI SDK. The SDK sends chat completions to api.refuseless.com/v1, which runs glm-5.3-abliterated. Only the base URL, the API key, and the model id change.Your appOpenAI SDK, unchangedapi.refuseless.com/v1POST /chat/completionsglm-5.3-abliteratedrefusal-edited weightsThree values change. Nothing else does.base URLapi.openai.com/v1→api.refuseless.com/v1API keyOPENAI_API_KEY→REFUSELESS_API_KEYmodelyour OpenAI model id→glm-5.3-abliterated
    Only three values change. The Python SDK calls the base URL base_url.
    Python
    from openai import OpenAI
    import os
    
    client = OpenAI(
        api_key=os.environ["REFUSELESS_API_KEY"],
        base_url="https://api.refuseless.com/v1",
    )
    
    response = client.chat.completions.create(
        model="glm-5.3-abliterated",
        messages=[
            {"role": "user", "content": "Summarize this function in one paragraph."},
        ],
    )
    print(response.choices[0].message.content)

    What stays the same?

    • Message roles. system, user, and assistant mean what they mean in the OpenAI shape.
    • The path. The SDK appends /chat/completions to the base URL. Do not also append /v1 in the base URL and in the path.
    • Streaming, if you already pass stream=True. Leave it. This page does not add a second client.

    Which errors will you see?

    • HTTP 401, "Missing bearer API key." The Authorization header never arrived. Check that the environment variable is set in the process that imports the SDK.
    • HTTP 401, "Invalid API key." The header arrived and the key is not one of ours. An OpenAI key will do this.
    • HTTP 404, code model_not_found, message "Unknown model." The id is not in the catalog. Copy one from GET /v1/models or the models page.
    • HTTP 404 on a path you invented. The error body lists the supported methods: chat completions, responses, completions, embeddings where the model offers them, and GET /v1/models.

    The Node SDK is the same idea with baseURL in camelCase. That page is here. Pricing stays on the pricing page, because a snippet that hardcodes a rate goes stale on purpose.

    Get an API keySee the lineup