• bitcoinBitcoin(BTC)$80,557.004.80%
  • ethereumEthereum(ETH)$2,424.107.19%
  • tetherTether(USDT)$1.000.04%
  • binancecoinBNB(BNB)$719.683.81%
  • rippleXRP(XRP)$1.313.94%
  • usd-coinUSDC(USDC)$1.000.02%
  • solanaSolana(SOL)$95.754.31%
  • tronTRON(TRX)$0.319314-0.81%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.051.54%
  • zcashZcash(ZEC)$1,291.377.43%
  • HyperliquidHyperliquid(HYPE)$84.561.47%
  • dogecoinDogecoin(DOGE)$0.0769373.65%
  • moneroMonero(XMR)$637.751.81%
  • USDSUSDS(USDS)$1.000.02%
  • whitebitWhiteBIT Coin(WBT)$77.955.50%
  • chainlinkChainlink(LINK)$11.455.33%
  • leo-tokenLEO Token(LEO)$9.340.39%
  • cardanoCardano(ADA)$0.1967575.11%
  • stellarStellar(XLM)$0.1679804.88%
  • bitcoin-cashBitcoin Cash(BCH)$281.793.68%
  • nearNEAR Protocol(NEAR)$4.005.39%
  • uniswapUniswap(UNI)$7.717.94%
  • daiDai(DAI)$1.000.00%
  • Ethena USDeEthena USDe(USDE)$1.000.06%
  • litecoinLitecoin(LTC)$56.235.62%
  • RainRain(RAIN)$0.005971-9.59%
  • CantonCanton(CC)$0.0988344.06%
  • avalanche-2Avalanche(AVAX)$8.754.05%
  • suiSui(SUI)$0.935.65%
  • USD1USD1(USD1)$1.000.07%
  • the-open-networkGram (prev. Toncoin)(GRAM)$1.171.24%
  • tether-goldTether Gold(XAUT)$4,062.963.80%
  • hedera-hashgraphHedera(HBAR)$0.0729236.01%
  • quant-networkQuant(QNT)$203.487.19%
  • Global DollarGlobal Dollar(USDG)$1.000.02%
  • shiba-inuShiba Inu(SHIB)$0.0000053.79%
  • BittensorBittensor(TAO)$235.725.93%
  • paypal-usdPayPal USD(PYUSD)$1.000.02%
  • crypto-com-chainCronos(CRO)$0.0520054.68%
  • Ripple USDRipple USD(RLUSD)$1.000.01%
  • EthenaEthena(ENA)$0.1818207.07%
  • Ondo US Dollar YieldOndo US Dollar Yield(USDY)$1.15-0.16%
  • okbOKB(OKB)$111.094.24%
  • Circle USYCCircle USYC(USYC)$1.140.01%
  • pepePepe(PEPE)$0.0000053.54%
  • aaveAave(AAVE)$132.745.85%
  • OndoOndo(ONDO)$0.4098406.77%
  • Pump.funPump.fun(PUMP)$0.0042890.92%
  • MemeCoreMemeCore(M)$0.85-1.11%
  • BlackRock USD Institutional Digital Liquidity FundBlackRock USD Institutional Digital Liquidity Fund(BUIDL)$1.000.00%
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
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

YOU MAY ALSO LIKE

Snap Has More Than 30 Million Paid Subscribers Across Snapchat+ And Other Plans

Atmospheric AI Secures $10M Seed for Procurement Modeling Push – Unite.AI

ShareTweetSendSharePin

Related Posts

Snap Has More Than 30 Million Paid Subscribers Across Snapchat+ And Other Plans
AI & Technology

Snap Has More Than 30 Million Paid Subscribers Across Snapchat+ And Other Plans

November 4, 2026
Atmospheric AI Secures M Seed for Procurement Modeling Push – Unite.AI
AI & Technology

Atmospheric AI Secures $10M Seed for Procurement Modeling Push – Unite.AI

November 4, 2026
Perplexity Adds Live Web Grounding to Its Decisions API – Unite.AI
AI & Technology

Perplexity Adds Live Web Grounding to Its Decisions API – Unite.AI

November 4, 2026
Pangram Expands Its AI Detection Tools To Video And Images
AI & Technology

Pangram Expands Its AI Detection Tools To Video And Images

November 4, 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
Macleods Pharma USA recalls thousands of blood pressure medication after pills fail quality test

Macleods Pharma USA recalls thousands of blood pressure medication after pills fail quality test

November 3, 2026
Current with Christine Romans – Oct. 2 | NBC News NOW

Current with Christine Romans – Oct. 2 | NBC News NOW

November 2, 2026
Clashes erupt between French police and protesters demanding better schools

Clashes erupt between French police and protesters demanding better schools

October 29, 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!