• bitcoinBitcoin(BTC)$78,993.00-0.84%
  • ethereumEthereum(ETH)$2,480.240.03%
  • tetherTether(USDT)$1.00-0.01%
  • binancecoinBNB(BNB)$740.27-0.56%
  • rippleXRP(XRP)$1.39-1.38%
  • usd-coinUSDC(USDC)$1.00-0.01%
  • solanaSolana(SOL)$104.05-1.62%
  • tronTRON(TRX)$0.334227-0.27%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.060.00%
  • zcashZcash(ZEC)$1,159.37-0.51%
  • HyperliquidHyperliquid(HYPE)$85.42-3.89%
  • dogecoinDogecoin(DOGE)$0.0897451.14%
  • RainRain(RAIN)$0.016331-2.86%
  • moneroMonero(XMR)$534.821.46%
  • USDSUSDS(USDS)$1.00-0.01%
  • chainlinkChainlink(LINK)$12.936.08%
  • whitebitWhiteBIT Coin(WBT)$72.84-0.67%
  • leo-tokenLEO Token(LEO)$9.15-1.89%
  • cardanoCardano(ADA)$0.2186970.41%
  • stellarStellar(XLM)$0.1900963.57%
  • bitcoin-cashBitcoin Cash(BCH)$260.632.23%
  • daiDai(DAI)$1.000.00%
  • Ethena USDeEthena USDe(USDE)$1.000.00%
  • litecoinLitecoin(LTC)$55.882.71%
  • uniswapUniswap(UNI)$6.87-0.98%
  • USD1USD1(USD1)$1.000.02%
  • CantonCanton(CC)$0.106278-2.99%
  • the-open-networkGram (prev. Toncoin)(GRAM)$1.41-0.47%
  • hedera-hashgraphHedera(HBAR)$0.0814781.39%
  • avalanche-2Avalanche(AVAX)$8.065.94%
  • suiSui(SUI)$0.812.98%
  • Global DollarGlobal Dollar(USDG)$1.00-0.01%
  • shiba-inuShiba Inu(SHIB)$0.0000050.69%
  • nearNEAR Protocol(NEAR)$2.33-1.55%
  • paypal-usdPayPal USD(PYUSD)$1.00-0.01%
  • BlackRock USD Institutional Digital Liquidity FundBlackRock USD Institutional Digital Liquidity Fund(BUIDL)$1.000.00%
  • crypto-com-chainCronos(CRO)$0.057150-0.28%
  • tether-goldTether Gold(XAUT)$4,410.31-0.25%
  • Circle USYCCircle USYC(USYC)$1.140.00%
  • MemeCoreMemeCore(M)$1.12-0.23%
  • BittensorBittensor(TAO)$256.075.61%
  • okbOKB(OKB)$114.851.76%
  • Ripple USDRipple USD(RLUSD)$1.00-0.01%
  • Ondo US Dollar YieldOndo US Dollar Yield(USDY)$1.14-0.36%
  • mantleMantle(MNT)$0.646.35%
  • AsterAster(ASTER)$0.771.90%
  • aaveAave(AAVE)$131.57-1.74%
  • pax-goldPAX Gold(PAXG)$4,412.37-0.33%
  • OndoOndo(ONDO)$0.3871433.62%
  • polkadotPolkadot(DOT)$1.0914.22%
TradePoint.io
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop
No Result
View All Result
TradePoint.io
No Result
View All Result

GLM-5.2 OpenAI-Compatible API: A Hands-On Guide to Reasoning Effort, Function Calling, and Long-Context Retrieval

June 23, 2026
in AI & Technology
Reading Time: 2 mins read
A A
GLM-5.2 OpenAI-Compatible API: A Hands-On Guide to Reasoning Effort, Function Calling, and Long-Context Retrieval
ShareShareShareShareShare

YOU MAY ALSO LIKE

Grupo Financiero Inbursa Adopts Harvey Across Its Legal Organization – Unite.AI

How To Find And Hide An App On Android Auto

import sys, subprocess
subprocess.run([sys.executable, "-m", "pip", "install", "-q", "-U", "openai"], check=False)
import os, re, json, time, getpass
from openai import OpenAI
PROVIDERS = {
   "zai":         {"base_url": "https://api.z.ai/api/paas/v4/",   "model": "glm-5.2",        "env": "ZAI_API_KEY"},
   "openrouter":  {"base_url": "https://openrouter.ai/api/v1",    "model": "z-ai/glm-5.2",   "env": "OPENROUTER_API_KEY"},
   "together":    {"base_url": "https://api.together.xyz/v1",     "model": "zai-org/GLM-5.2","env": "TOGETHER_API_KEY"},
   "requesty":    {"base_url": "https://router.requesty.ai/v1",   "model": "zai/glm-5.2",    "env": "REQUESTY_API_KEY"},
   "huggingface": {"base_url": "https://router.huggingface.co/v1","model": "zai-org/GLM-5.2","env": "HF_TOKEN"},
}
PROVIDER = "zai"
CFG   = PROVIDERS[PROVIDER]
MODEL = CFG["model"]
def load_api_key(env_name):
   try:
       from google.colab import userdata
       v = userdata.get(env_name)
       if v: return v
   except Exception:
       pass
   if os.environ.get(env_name):
       return os.environ[env_name]
   return getpass.getpass(f"Enter your {env_name}: ")
client = OpenAI(api_key=load_api_key(CFG["env"]), base_url=CFG["base_url"])
PRICE_IN_PER_M, PRICE_OUT_PER_M = 1.40, 4.40
_USAGE = {"in": 0, "out": 0, "calls": 0}
def _track(usage):
   if usage:
       _USAGE["in"]    += getattr(usage, "prompt_tokens", 0) or 0
       _USAGE["out"]   += getattr(usage, "completion_tokens", 0) or 0
       _USAGE["calls"] += 1
def get_reasoning(obj):
   """Pull GLM's hidden reasoning trace from a message/delta (a provider-extra field)."""
   val = getattr(obj, "reasoning_content", None)
   if val: return val
   extra = getattr(obj, "model_extra", None) or {}
   if extra.get("reasoning_content"): return extra["reasoning_content"]
   try:    return obj.to_dict().get("reasoning_content")
   except Exception: return None
def chat(messages, effort=None, thinking=True, tools=None, tool_choice="auto",
        stream=False, max_tokens=2048, temperature=1.0, tool_stream=False):
   """
   effort:   None | "high" | "max"   (GLM-5.2 thinking-effort level; max is the model default)
   thinking: True -> deep thinking on; False -> off (fast, cheap, low-latency)
   GLM-specific params go through extra_body so any OpenAI client works.
   """
   extra = {"thinking": {"type": "enabled" if thinking else "disabled"}}
   if effort and thinking: extra["reasoning_effort"] = effort
   if tool_stream:         extra["tool_stream"] = True
   kwargs = dict(model=MODEL, messages=messages, max_tokens=max_tokens,
                 temperature=temperature, stream=stream, extra_body=extra)
   if tools:
       kwargs.update(tools=tools, tool_choice=tool_choice)
   if stream:
       kwargs["stream_options"] = {"include_usage": True}
   return client.chat.completions.create(**kwargs)

Credit: Source link

ShareTweetSendSharePin

Related Posts

Grupo Financiero Inbursa Adopts Harvey Across Its Legal Organization – Unite.AI
AI & Technology

Grupo Financiero Inbursa Adopts Harvey Across Its Legal Organization – Unite.AI

September 7, 2026
How To Find And Hide An App On Android Auto
AI & Technology

How To Find And Hide An App On Android Auto

September 7, 2026
How To Change Siri’s Voice
AI & Technology

How To Change Siri’s Voice

September 7, 2026
What Is a Foundation Model? How General-Purpose AI Is Built and Adapted – Unite.AI
AI & Technology

What Is a Foundation Model? How General-Purpose AI Is Built and Adapted – Unite.AI

September 7, 2026
Next Post
Trump under pressure to reveal text of Iran deal

Trump under pressure to reveal text of Iran deal

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

No Result
View All Result
How Bob Iger’s future ‘ownership’ of LA Lakers has been exaggerated

How Bob Iger’s future ‘ownership’ of LA Lakers has been exaggerated

September 3, 2026
Orca is seen torpedoing a sunfish, causing it to explode

Orca is seen torpedoing a sunfish, causing it to explode

September 6, 2026
Measles cases hit 35-year high in 2026

Measles cases hit 35-year high in 2026

September 5, 2026

About

Learn more

Our Services

Legal

Privacy Policy

Terms of Use

Bloggers

Learn more

Article Links

Contact

Advertise

Ask us anything

©2020- TradePoint.io - All rights reserved!

Tradepoint.io, being just a publishing and technology platform, is not a registered broker-dealer or investment adviser. So we do not provide investment advice. Rather, brokerage services are provided to clients of Tradepoint.io by independent SEC-registered broker-dealers and members of FINRA/SIPC. Every form of investing carries some risk and past performance is not a guarantee of future results. “Tradepoint.io“, “Instant Investing” and “My Trading Tools” are registered trademarks of Apperbuild, LLC.

This website is operated by Apperbuild, LLC. We have no link to any brokerage firm and we do not provide investment advice. Every information and resource we provide is solely for the education of our readers. © 2020 Apperbuild, LLC. All rights reserved.

No Result
View All Result
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop

© 2023 - TradePoint.io - All Rights Reserved!