• bitcoinBitcoin(BTC)$62,379.00-2.67%
  • ethereumEthereum(ETH)$1,649.30-5.55%
  • tetherTether(USDT)$1.000.01%
  • binancecoinBNB(BNB)$571.89-3.52%
  • usd-coinUSDC(USDC)$1.000.01%
  • rippleXRP(XRP)$1.10-2.92%
  • solanaSolana(SOL)$68.76-6.89%
  • tronTRON(TRX)$0.329794-0.25%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.041.48%
  • HyperliquidHyperliquid(HYPE)$62.95-6.57%
  • dogecoinDogecoin(DOGE)$0.079105-5.35%
  • USDSUSDS(USDS)$1.000.00%
  • RainRain(RAIN)$0.0158139.74%
  • leo-tokenLEO Token(LEO)$9.560.27%
  • zcashZcash(ZEC)$422.23-6.96%
  • stellarStellar(XLM)$0.192176-8.93%
  • whitebitWhiteBIT Coin(WBT)$50.71-3.67%
  • moneroMonero(XMR)$316.61-2.26%
  • CantonCanton(CC)$0.1502160.08%
  • cardanoCardano(ADA)$0.152617-5.10%
  • chainlinkChainlink(LINK)$7.53-5.79%
  • LABLAB(LAB)$16.258.72%
  • USD1USD1(USD1)$1.000.01%
  • daiDai(DAI)$1.00-0.02%
  • Ethena USDeEthena USDe(USDE)$1.000.00%
  • the-open-networkGram (prev. Toncoin)(GRAM)$1.59-4.04%
  • bitcoin-cashBitcoin Cash(BCH)$188.96-5.38%
  • MemeCoreMemeCore(M)$2.88-1.44%
  • hedera-hashgraphHedera(HBAR)$0.077258-2.37%
  • litecoinLitecoin(LTC)$43.34-3.35%
  • Circle USYCCircle USYC(USYC)$1.130.00%
  • Global DollarGlobal Dollar(USDG)$1.000.00%
  • suiSui(SUI)$0.68-4.03%
  • paypal-usdPayPal USD(PYUSD)$1.00-0.02%
  • shiba-inuShiba Inu(SHIB)$0.000005-3.60%
  • avalanche-2Avalanche(AVAX)$6.14-1.92%
  • crypto-com-chainCronos(CRO)$0.056440-4.49%
  • nearNEAR Protocol(NEAR)$1.98-7.68%
  • tether-goldTether Gold(XAUT)$4,097.57-2.16%
  • BlackRock USD Institutional Digital Liquidity FundBlackRock USD Institutional Digital Liquidity Fund(BUIDL)$1.000.00%
  • Ondo US Dollar YieldOndo US Dollar Yield(USDY)$1.141.21%
  • BittensorBittensor(TAO)$218.64-6.01%
  • worldcoin-wldWorldcoin(WLD)$0.57-8.91%
  • pax-goldPAX Gold(PAXG)$4,103.65-2.20%
  • World Liberty FinancialWorld Liberty Financial(WLFI)$0.057373-3.01%
  • uniswapUniswap(UNI)$2.84-5.70%
  • mantleMantle(MNT)$0.51-4.22%
  • AsterAster(ASTER)$0.62-2.99%
  • okbOKB(OKB)$77.801.93%
  • Ripple USDRipple USD(RLUSD)$1.00-0.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

Prime Intellect Releases prime-rl 0.6.0 to Train Trillion-Parameter MoE Models on Agentic RL Workloads

Meta Is ‘Pausing’ Employee Tracking Program After It Let The Whole Company See Sensitive Data

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

Prime Intellect Releases prime-rl 0.6.0 to Train Trillion-Parameter MoE Models on Agentic RL Workloads
AI & Technology

Prime Intellect Releases prime-rl 0.6.0 to Train Trillion-Parameter MoE Models on Agentic RL Workloads

June 23, 2026
Meta Is ‘Pausing’ Employee Tracking Program After It Let The Whole Company See Sensitive Data
AI & Technology

Meta Is ‘Pausing’ Employee Tracking Program After It Let The Whole Company See Sensitive Data

June 22, 2026
xAI Launches /goal in Grok Build, Adding Long-Running Autonomous Execution With Built-In Verification for Multi-Step Coding Tasks
AI & Technology

xAI Launches /goal in Grok Build, Adding Long-Running Autonomous Execution With Built-In Verification for Multi-Step Coding Tasks

June 22, 2026
Alibaba’s AI video model rises to No. 2 in global rankings, as OpenAI’s Sora and ByteDance’s Seedance fall away
AI & Technology

Alibaba’s AI video model rises to No. 2 in global rankings, as OpenAI’s Sora and ByteDance’s Seedance fall away

June 22, 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
Trump-endorsed Barry Moore wins Republican primary runoff in Alabama Senate race

Trump-endorsed Barry Moore wins Republican primary runoff in Alabama Senate race

June 23, 2026
Monkey in South Florida steals mangoes off people’s trees

Monkey in South Florida steals mangoes off people’s trees

June 22, 2026
Will Israel Abide by the U.S.-Iran MOU?; Supreme Court Rules on Gun Rights Restrictions – June 18

Will Israel Abide by the U.S.-Iran MOU?; Supreme Court Rules on Gun Rights Restrictions – June 18

June 21, 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!