• bitcoinBitcoin(BTC)$66,331.001.63%
  • ethereumEthereum(ETH)$1,929.461.02%
  • tetherTether(USDT)$1.000.01%
  • binancecoinBNB(BNB)$572.630.05%
  • usd-coinUSDC(USDC)$1.000.00%
  • rippleXRP(XRP)$1.142.51%
  • solanaSolana(SOL)$78.210.39%
  • tronTRON(TRX)$0.3292071.03%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.010.47%
  • HyperliquidHyperliquid(HYPE)$60.80-2.56%
  • dogecoinDogecoin(DOGE)$0.0735371.65%
  • RainRain(RAIN)$0.01554010.21%
  • USDSUSDS(USDS)$1.000.00%
  • leo-tokenLEO Token(LEO)$9.72-0.09%
  • zcashZcash(ZEC)$532.14-1.73%
  • whitebitWhiteBIT Coin(WBT)$57.751.39%
  • moneroMonero(XMR)$355.784.48%
  • stellarStellar(XLM)$0.1930023.12%
  • cardanoCardano(ADA)$0.1748892.88%
  • chainlinkChainlink(LINK)$8.701.42%
  • CantonCanton(CC)$0.1271872.13%
  • daiDai(DAI)$1.000.01%
  • bitcoin-cashBitcoin Cash(BCH)$225.081.74%
  • the-open-networkGram (prev. Toncoin)(GRAM)$1.589.85%
  • USD1USD1(USD1)$1.000.00%
  • Ethena USDeEthena USDe(USDE)$1.000.00%
  • litecoinLitecoin(LTC)$46.61-1.12%
  • Global DollarGlobal Dollar(USDG)$1.000.08%
  • suiSui(SUI)$0.770.95%
  • hedera-hashgraphHedera(HBAR)$0.0704935.64%
  • Circle USYCCircle USYC(USYC)$1.13-0.01%
  • avalanche-2Avalanche(AVAX)$6.60-0.16%
  • paypal-usdPayPal USD(PYUSD)$1.00-0.01%
  • crypto-com-chainCronos(CRO)$0.0585711.38%
  • BlackRock USD Institutional Digital Liquidity FundBlackRock USD Institutional Digital Liquidity Fund(BUIDL)$1.000.00%
  • tether-goldTether Gold(XAUT)$4,116.812.10%
  • nearNEAR Protocol(NEAR)$1.93-2.97%
  • shiba-inuShiba Inu(SHIB)$0.0000040.15%
  • uniswapUniswap(UNI)$3.680.71%
  • Ondo US Dollar YieldOndo US Dollar Yield(USDY)$1.140.37%
  • OndoOndo(ONDO)$0.40139311.71%
  • BittensorBittensor(TAO)$201.183.84%
  • pax-goldPAX Gold(PAXG)$4,115.892.14%
  • World Liberty FinancialWorld Liberty Financial(WLFI)$0.0571150.45%
  • okbOKB(OKB)$82.240.88%
  • AsterAster(ASTER)$0.63-0.88%
  • HTX DAOHTX DAO(HTX)$0.000002-0.11%
  • Ripple USDRipple USD(RLUSD)$1.000.02%
  • MemeCoreMemeCore(M)$1.18-0.80%
  • usddUSDD(USDD)$1.000.01%
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

Poolside Releases Laguna S 2.1, an Open-Weight Agentic Coding Model Punching Above Its Weight Class on SWE-Bench Multilingual

Poolside drops Laguna S 2.1, an open-weight coding model that beats rivals 10x its size

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

Poolside Releases Laguna S 2.1, an Open-Weight Agentic Coding Model Punching Above Its Weight Class on SWE-Bench Multilingual
AI & Technology

Poolside Releases Laguna S 2.1, an Open-Weight Agentic Coding Model Punching Above Its Weight Class on SWE-Bench Multilingual

July 22, 2026
Poolside drops Laguna S 2.1, an open-weight coding model that beats rivals 10x its size
AI & Technology

Poolside drops Laguna S 2.1, an open-weight coding model that beats rivals 10x its size

July 21, 2026
France Will Ban Social Media For Children Under 15
AI & Technology

France Will Ban Social Media For Children Under 15

July 21, 2026
Stop adding more GPUs: Weka’s new storage platform reduces load by caching 100% of an AI model’s pre-calculated tokens
AI & Technology

Stop adding more GPUs: Weka’s new storage platform reduces load by caching 100% of an AI model’s pre-calculated tokens

July 21, 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
BNY Mellon Appreciation Fund Q2 2026 Commentary

BNY Mellon Appreciation Fund Q2 2026 Commentary

July 19, 2026
How To Use Claude’s Reflect Dashboard And Learn When It’s Time To Touch Grass

How To Use Claude’s Reflect Dashboard And Learn When It’s Time To Touch Grass

July 19, 2026
Apple Has Banned Home Service Content On Upcoming Maps Ads

Apple Has Banned Home Service Content On Upcoming Maps Ads

July 18, 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!