Skip to content

Instantly share code, notes, and snippets.

@olafgeibig
Last active September 19, 2025 04:09
Show Gist options
  • Select an option

  • Save olafgeibig/925ed73f10a5b99d891c0185580f4e42 to your computer and use it in GitHub Desktop.

Select an option

Save olafgeibig/925ed73f10a5b99d891c0185580f4e42 to your computer and use it in GitHub Desktop.
Z.ai subscription with opencode

Z.ai subscription with opencode

Now Z.ai has an official solution to use the package. See below.

Create a custom provider

First we need to create a custom provider for the Z.ai anthropic API. Follow the instructions for adding a custom provider to opencode.

  • Name it zai-anthropic
  • Enter your API-key

Configure the custom-provider

Edit opencode.json and add this:

    "provider": {
        "zai-anthropic": {
            "npm": "@ai-sdk/anthropic",
            "options": {
                "baseURL": "https://api.z.ai/api/anthropic/v1"
            },
            "models": {
                "glm-4.5": {
                    "name": "glm-4.5"
                }
            }
        }

Make this model default if you wish:

    "model": "zai-anthropic/glm-4.5",

Official solution from Z.ai

Now there is the official solution to support opencode and others. I switched and it works perfectly. Great job Z.ai.

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "zai": {
      "options": {
        "baseURL": "https://api.z.ai/api/coding/paas/v4"
      }
    }
  }
}
@nathabonfim59
Copy link

nathabonfim59 commented Sep 3, 2025

Thanks for the config!

Based on their docs, it seems they support both models for the subscription.

    "zai-anthropic": {
      "npm": "@ai-sdk/anthropic",
      "options": {
        "baseURL": "https://api.z.ai/api/anthropic/v1"
      },
      "models": {
        "glm-4.5-air": {
          "name": "glm-4.5-air"
        },
        "glm-4.5": {
          "name": "glm-4.5"
        }
      }
    }

@iFedyna
Copy link

iFedyna commented Sep 3, 2025

I'm successfully using LiteLLM with the ZAI-GLM-4.5 model.
I've been testing for the last few hours, everything is great. I use it in GitHub Copilot also works in Cline.

The following configuration is working perfectly:

model_name: "ZAI-GLM-4.5"
litellm_params:
  model: "anthropic/GLM-4.5"
  api_base: "https://api.z.ai/api/anthropic"
  api_key: os.environ/ZAI_CODE

this option simulates working in Claude code

model_name: "ZAI-GLM-4.5" 
litellm_params:
  model: "anthropic/claude-sonnet-4-20250514" 
  api_base: "https://api.z.ai/api/anthropic"
  api_key: os.environ/ZAI_CODE

@konstantinosbotonakis
Copy link

konstantinosbotonakis commented Sep 3, 2025

Worked for me in OpenRouter as well. Worked with Claude Code as well. Better results with Claude Code.

@olafgeibig
Copy link
Author

@iFedyna, first I also thought I'll use LiteLLM. It's such a great tool for proxying. But opencode has such flexible provider config options that it wasn't neccessary.

@olafgeibig
Copy link
Author

olafgeibig commented Sep 3, 2025

@nathabonfim59 nice, but what is your use case for the air model? Faster sub-agents? Do you have even more requests with air? Anybody knows how they meter it or where I can see my remaining volume?

@iFedyna
Copy link

iFedyna commented Sep 4, 2025

@olafgeibig It was important for me to find a limit and LiteLLM allows you to count. Yesterday I used 32,000,000 tokens and made 540 calls to the model my lite plan, even with this volume I did not reach the limit. I also tried air in the calls of the tools very badly with the copilot.

Most likely they have an internal counting system. I did not find information on the official website.

Up to about 120 prompts per 5-hour cycle

A “prompt” refers to a single user query sent. It typically triggers around 15–20 model calls, consuming hundreds of thousands of tokens. See the FAQ for details.

based on this information from 1200 model calls in 5 hours limit.
Compared to others, this is the best offer there can be.

@olafgeibig
Copy link
Author

@iFedyna That's amazing. What a crazy good offer.

@iFedyna
Copy link

iFedyna commented Sep 5, 2025

@olafgeibig today I reached the limit of 190 requests and 9000000 tokens. And I have -0.08 cents on my account. So the counting system is a little different than I thought. In three days I have 1333 requests 73 million tokens

@konstantinosbotonakis
Copy link

@olafgeibig today I reached the limit of 190 requests and 9000000 tokens. And I have -0.08 cents on my account. So the counting system is a little different than I thought. In three days I have 1333 requests 73 million tokens

are you working on anything and using so many tokens / requests or are you just trying to see the limit of the service?

@iFedyna
Copy link

iFedyna commented Sep 5, 2025

@konstantinosbotonakis creating projects. Calculating just for myself to see which plan suits me best for my tasks. For example, Rovo Dev CLI give 20 million per day without restrictions on requests to choose from two models Sonnet 4 and GPT5. Price 7.53 usd. I also use it to see who can handle which tasks and how.

@nathabonfim59
Copy link

@nathabonfim59 nice, but what is your use case for the air model? Faster sub-agents?

Mostly /compact and I have an agent to fetch parts of the documentation and feed back to the main one.

@olafgeibig
Copy link
Author

@iFedyna thank you. That is valuable information to judge the plan. So the 190 requests and 9000000 tokens were consumed within a 5 hour window, I guess. Really a great offer.

@olafgeibig
Copy link
Author

@nathabonfim59 Good idea. Is compact significantly faster then?

@nathabonfim59
Copy link

They are running a promo for $36 for the whole year. A WHOLE FREAKING YEAR!! I don't even know what's going on at this point.

The bigger models even support vision, but I think it's restricted to the Pro/Max plan.

They also released the "official" rate limits, but from what I've tested, it's not being currently enforced.

Image
image
image

https://z.ai/subscribe

Note

Full transparency, THIS IS an affiliate link. I think I get less than $1 worth of inference for each subscription.
It won't cost anything more for you, and we both get something out of it. ;)
If not, just copy the link https://z.ai/subscribe and you're good to go.

I think @olafgeibig should put his one up top, he was the one who created this gist, it's only fair.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment