PageSourceSearch

https://xyc.ai/static/js/async/1581.9b13de788d.js

js xyc.ai collected 2026-10-05 14:38:05 UTC 13,712 bytes, 51 lines download raw bytes

1"use strict";(self.rspackChunknewapi_web=self.rspackChunknewapi_web||[]).push([[1581],{21292(e,t,s){s.d(t,{NG:()=>u,gZ:()=>x});var r=s(72361),n=s(68413),a=s(93294),l=s(61631),o=s(81204),i=s(46775);let c=(0,n.createContext)({code:""}),d={name:"line-numbers",line(e,t){e.children.unshift({type:"element",tagName:"span",properties:{className:["inline-block","min-w-10","mr-4","text-right","select-none","text-muted-foreground"]},children:[{type:"text",value:String(t)}]})}};async function m(e,t){let s=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return(0,a.Yz)(e,{lang:t,themes:{light:"one-light",dark:"one-dark-pro"},transformers:s?[d]:[]})}let u=e=>{let{code:t,language:s,showLineNumbers:a=!1,className:l,children:i,...d}=e,[u,x]=(0,n.useState)("");return(0,n.useEffect)(()=>{let e=!1;return m(t,s,a).then(t=>{e||x(t)}),()=>{e=!0}},[t,s,a]),(0,r.jsx)(c.Provider,{value:{code:t},children:(0,r.jsx)("div",{className:(0,o.cn)("group bg-background text-foreground relative w-full overflow-hidden rounded-md border",l),...d,children:(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)("div",{className:"[&>pre]:bg-background! [&>pre]:text-foreground! overflow-hidden [&_code]:font-mono [&_code]:text-sm [&>pre]:m-0 [&>pre]:p-4 [&>pre]:text-sm",dangerouslySetInnerHTML:{__html:u}}),i&&(0,r.jsx)("div",{className:"absolute top-2 right-2 flex items-center gap-2",children:i})]})})})},x=e=>{let{onCopy:t,onError:s,timeout:a=2e3,children:d,className:m,...u}=e,[x,p]=(0,n.useState)(!1),{code:h}=(0,n.useContext)(c),g=async()=>{if("u"<typeof window||!navigator?.clipboard?.writeText)return void s?.(Error("Clipboard API not available"));try{await navigator.clipboard.writeText(h),p(!0),t?.(),setTimeout(()=>p(!1),a)}catch(e){s?.(e)}},b=x?l.Srz:l.TdU;return(0,r.jsx)(i.$,{className:(0,o.cn)("shrink-0",m),onClick:g,size:"icon",variant:"ghost",...u,children:d??(0,r.jsx)(b,{size:14})})}},22268(e,t,s){s.r(t),s.d(t,{component:()=>S});var r=s(72361),n=s(6702),a=s(99170),l=s(67267),o=s(68413),i=s(30464),c=s(34151),d=s(21292);let m={curl:"curl",python:"python",nodejs:"nodejs"},u={curl:"bash",python:"python",nodejs:"javascript"},x="gpt-5.2";function p(){let e,{t}=(0,n.Bd)(),{status:s}=(0,i.s)(),[a,l]=(0,o.useState)("curl"),p=(0,o.useMemo)(()=>{let e=s?.server_address;return e&&"string"==typeof e?e.replace(/\/$/,""):"u">typeof window?window.location.origin:"https://api.example.com"},[s]),h=(e=`${p}/v1/chat/completions`,"curl"===a?`curl -X POST "${e}" \\
2  -H "Authorization: Bearer YOUR_API_KEY" \\
3  -H "Content-Type: application/json" \\
4  -d '{
5    "model": "${x}",
6    "messages": [
7      {
8        "role": "user",
9        "content": "Hello World"
10      }
11    ],
12    "stream": true,
13    "temperature": 0.7,
14    "max_tokens": 1000
15  }'`:"python"===a?`from openai import OpenAI
16
17client = OpenAI(
18    api_key="YOUR_API_KEY",
19    base_url="${p}/v1",
20)
21
22response = client.chat.completions.create(
23    model="${x}",
24    messages=[
25        {"role": "user", "content": "Hello World"},
26    ],
27    stream=True,
28    temperature=0.7,
29    max_tokens=1000,
30)
31
32for chunk in response:
33    print(chunk.choices[0].delta.content or "", end="")`:`import OpenAI from "openai";
34
35const client = new OpenAI({
36  apiKey: "YOUR_API_KEY",
37  baseURL: "${p}/v1",
38});
39
40const stream = await client.chat.completions.create({
41  model: "${x}",
42  messages: [{ role: "user", content: "Hello World" }],
43  stream: true,
44  temperature: 0.7,
45  max_tokens: 1000,
46});
47
48for await (const chunk of stream) {
49  process.stdout.write(chunk.choices[0]?.delta?.content || "");
50}`);return(0,r.jsxs)("section",{className:"space-y-3",children:[(0,r.jsx)("h2",{className:"text-base font-semibold",children:t("Call examples")}),(0,r.jsx)(c.tU,{value:a,onValueChange:e=>l(e),children:(0,r.jsx)(c.j7,{className:"bg-transparent p-0",children:Object.keys(m).map(e=>(0,r.jsx)(c.Xi,{value:e,className:"px-3 text-sm",children:m[e]},e))})}),(0,r.jsx)(d.NG,{code:h,language:u[a],className:"bg-surface-active [&>div>div:first-child>pre]:bg-surface-active!",children:(0,r.jsx)(d.gZ,{})}),(0,r.jsxs)("p",{className:"text-muted-foreground text-xs",children:[t("Replace")," ",(0,r.jsx)("code",{className:"bg-surface-active rounded px-1 py-0.5 font-mono text-[11px]",children:"YOUR_API_KEY"})," ",t("with the API key from your token settings.")]})]})}var h=s(92170);async function g(e){try{let t=performance.now();await fetch(e,{method:"HEAD",mode:"no-cors",cache:"no-cache"});let s=performance.now();return{latency:Math.round(s-t),testing:!1,error:!1}}catch(e){return{latency:null,testing:!1,error:!0}}}var b=s(61631),f=s(81204),v=s(46775),j=s(3088);let y={blue:"bg-blue-500",green:"bg-emerald-500",cyan:"bg-cyan-500",purple:"bg-purple-500",pink:"bg-sky-500",red:"bg-red-500",orange:"bg-orange-500",amber:"bg-amber-500",yellow:"bg-yellow-400",lime:"bg-lime-500","light-green":"bg-green-400",teal:"bg-teal-500","light-blue":"bg-sky-4
5000",indigo:"bg-indigo-500",violet:"bg-violet-500",grey:"bg-gray-400",slate:"bg-slate-500"};function N(e){var t,s;let{t:a}=(0,n.Bd)(),{item:l,status:o}=e,i=l.url.trim().replace(/\/+$/,"").replace(/\/v1(\/chat\/completions)?$/i,""),c=i.replace(/^http/i,"ws"),d=[{url:i,hint:a("For most SDKs, such as OpenAI, LiteLLM, etc."),highlight:!0},{url:`${i}/v1`,hint:a("For clients that require the /v1 suffix.")},{url:`${i}/v1/chat/completions`,hint:a("For requests made directly via cURL or fetch to the chat endpoint.")},{url:`${c}/v1/responses`,hint:a("For Codex websocket responses mode (wss).")},{url:`${i}/v1/video/generations`,hint:a("Submit a video generation task (POST), returns a task_id. For Veo / Seedance / Dreamina, etc.")},{url:`${i}/v1/video/generations/{task_id}`,hint:a("Poll task status (GET). When status is SUCCESS, the response contains result_url.")},{url:`${i}/v1/videos/{task_id}/content`,hint:a("Download the generated video (GET), returns video/mp4.")}];return(0,r.jsxs)("div",{className:(0,f.cn)("flex flex-col gap-3 px-4 py-3 transition-colors","hover:bg-surface-hover",!e.isLast&&"border-border/60 border-b"),children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:(0,f.cn)("size-2 shrink-0 rounded-full",(t=l.color)?y[t]??y.blue:y.blue)}),(0,r.jsx)("span",{className:"truncate text-sm font-semibold",children:l.route}),e.recommended&&(0,r.jsx)("span",{className:"border-primary/30 bg-primary/10 text-primary shrink-0 rounded-full border px-1.5 py-px text-[10px] font-medium",children:a("Recommended")}),(0,r.jsxs)("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[o.testing&&(0,r.jsx)(j.Wh,{label:a("Testing..."),variant:"warning",className:"animate-pulse",showDot:!1,copyable:!1}),null!==o.latency&&!o.testing&&(0,r.jsx)(j.Wh,{variant:"success",label:`${o.latency}${a("ms")}`,className:(0,f.cn)("font-mono font-medium",(s=o.latency)<200?"text-success":s<500?"text-warning":"text-destructive"),showDot:!1,copyable:!1}),o.error&&(0,r.jsx)(j.Wh,{label:a("N/A"),variant:"neutral",showDot:!1,copyable:!1}),(0,r.jsx)(v.$,{variant:"ghost",size:"icon",onClick:()=>e.onTest(i),disabled:o.testing,className:"size-7",title:a("Test Latency"),"aria-label":a("Test Latency"),children:(0,r.jsx)(b.KqI,{className:(0,f.cn)("size-3.5",o.testing&&"animate-pulse")})}),(0,r.jsx)(v.$,{variant:"ghost",size:"icon",onClick:()=>{let e,t;return e=encodeURIComponent(i),t=`https://www.tcptest.cn/http/${e}`,void window.open(t,"_blank","noopener,noreferrer")},className:"size-7",title:a("External Speed Test"),"aria-label":a("External Speed Test"),children:(0,r.jsx)(b._I2,{className:"size-3.5"})})]})]}),(0,r.jsx)("div",{className:"flex flex-col gap-2 sm:pl-4",children:d.map(e=>(0,r.jsxs)("div",{className:"flex items-start gap-2",children:[(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsx)("code",{className:"text-foreground/90 block font-mono text-xs break-all sm:text-sm",children:e.url}),(0,r.jsx)("p",{className:(0,f.cn)("mt-0.5 text-xs leading-relaxed",e.highlight?"rounded-md border border-blue-200 bg-blue-50 px-2.5 py-1.5 font-medium text-blue-800 dark:border-blue-800/60 dark:bg-blue-950/50 dark:text-blue-100":"text-muted-foreground/70"),children:e.hint})]}),(0,r.jsx)(h.i,{value:e.url,variant:"ghost",size:"icon",className:"size-7 shrink-0",iconClassName:"size-3.5",tooltip:a("Copy URL"),"aria-label":a("Copy URL")})]},e.url))})]})}function k(){let e,{t}=(0,n.Bd)(),{items:s,loading:a}=function(e,t){let{status:s,loading:r}=(0,i.s)();return{items:!!s&&!1!==s[e]&&s?.[t]||[],loading:r}}("api_info_enabled","api_info"),[l,c]=(0,o.useState)({}),d=(0,o.useCallback)(async e=>{c(t=>({...t,[e]:{latency:null,testing:!0,error:!1}}));let t=await g(e);c(s=>({...s,[e]:t}))},[]);if(a||!s.length)return null;let m=(e=s.find(e=>{let t=`${e.route} ${e.url} ${e.description}`.toLowerCase();return/direct|recommend|main|主|直连|推荐/.test(t)}),(e??s[0])?.url),u=m?`${m.trim().replace(/\/+$/,"").replace(/\/v1(\/chat\/completions)?$/i,"")}/api/usage/token`:"/api/usage/token";return(0,r.jsxs)("section",{id:"api-endpoints",className:"scroll-mt-4 space-y-3",children:[(0,r.jsxs)("div",{className:"space-y-1",children:[(0,r.jsx)("h2",{className:"text-base font-semibold",children:t("API Endpoints")}),(0,r.jsx)("p",{className:"text-muted-foreground text-xs leading-relaxed",children:t("Set the Base URL of your client to one of the endpoints below. Use the Test button to measure latency and pick the fastest route for your region.")})]}),(0,r.jsx)("div",{className:"border-border/70 divide-border/60 bg-surface-active divide-y overflow-hidden rounded-lg border",children:s.map((e,t)=>(0,r.jsx)(N,{item:e,status:l[e.url]||{latency:null,testing:!1,error:!1},recommended:e.url===m,isLast:t===s.length-1,onTest:d},e.url))}),(0,r.jsx)("div",{className:"border-border/70 bg-surface-active rounded-lg border px-4 py-3",children:(0,r.jsx)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start",children:(0,r.jsxs)("div",{className:"min-w-0 flex-1 space-y-2",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsx)("span",{className:"rounded-full border border-emerald-500/25 bg-emerald-500/10 px-2 py-0.5 text-[11px] font-semibold text-emerald-700",children:"GET"}),(0,r.jsx)("h3",{className:"text-sm font-semibold",children:t("Check balance with an API key")})]}),(0,r.jsx)("p",{className:"text-muted-foreground text-xs leading-relaxed",children:t("Use any API key to view its total, used, and remaining quota, model restrictions, and expiration time. Send Bearer sk-xxxx in the Authorization header.")}),(0,r.jsxs)("div",{className:"bg-background/70 border-border/60 flex items-start gap-2 rounded-lg border px-3 py-2",children:[(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsx)("code",{className:"text-foreground
50/90 block font-mono text-xs break-all sm:text-sm",children:u}),(0,r.jsx)("p",{className:"text-muted-foreground/70 mt-0.5 font-mono text-[11px] break-all",children:"Authorization: Bearer sk-xxxx"})]}),(0,r.jsx)(h.i,{value:`curl ${u} \\
51  -H "Authorization: Bearer sk-xxxx"`,variant:"ghost",size:"icon",className:"size-7 shrink-0",iconClassName:"size-3.5",tooltip:t("Copy cURL"),"aria-label":t("Copy cURL")})]})]})})})]})}var w=s(42925),C=s(83476),_=s(82799);function $(){let{t:e}=(0,n.Bd)(),t=(0,_.Z)(),{status:s}=(0,i.s)(),a=s?.docs_link||"https://docs.xyc.ai",l=[{no:"01",title:e("Create API key"),desc:e("Create an API key and keep it safe."),onClick:()=>void t({to:"/keys"})},{no:"02",title:e("View examples"),desc:e("See the call examples below — cURL, Python, Nodejs.")},{no:"03",title:e("Send request"),desc:e("Connect to the AI services we provide.")}];return(0,r.jsxs)("section",{className:"space-y-3",children:[(0,r.jsx)("h2",{className:"text-base font-semibold",children:e("Quick Start")}),(0,r.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-4",children:[l.map(e=>(0,r.jsxs)("button",{type:"button",onClick:e.onClick,disabled:!e.onClick,className:(0,f.cn)("bg-card border-border/70 flex flex-col gap-2 rounded-lg border p-4 text-left transition-colors",e.onClick?"hover:border-border cursor-pointer":"cursor-default"),children:[(0,r.jsxs)("span",{className:"text-muted-foreground/70 text-sm font-medium tabular-nums",children:[e.no,"."]}),(0,r.jsx)("span",{className:"text-foreground text-sm font-semibold",children:e.title}),(0,r.jsx)("span",{className:"text-muted-foreground text-xs leading-relaxed",children:e.desc})]},e.no)),(0,r.jsxs)("a",{href:a,target:"_blank",rel:"noreferrer",className:(0,f.cn)("flex flex-col gap-2 rounded-lg border p-4 text-left transition-colors","border-border/70 bg-surface-active","hover:border-border hover:bg-surface-hover"),children:[(0,r.jsx)("span",{className:"text-primary bg-background flex size-7 items-center justify-center rounded-lg",children:(0,r.jsx)(b.iUU,{className:"size-4"})}),(0,r.jsx)("span",{className:"text-foreground text-sm font-semibold",children:e("API Reference")}),(0,r.jsx)("span",{className:"text-muted-foreground text-xs leading-relaxed",children:e("View the full API reference and guides.")})]})]})]})}var A=s(34093);let S=function(){let{t:e}=(0,n.Bd)();return(0,a.H)(e("Endpoint Settings")),(0,r.jsxs)(C.E,{children:[(0,r.jsx)(l.Ni,{children:(0,r.jsx)(l.Ni.Content,{children:(0,r.jsxs)("div",{className:"mx-auto w-full max-w-3xl space-y-8",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5 text-sm leading-5",children:[(0,r.jsx)("span",{className:"text-text-tertiary",children:e("Connect with us")}),(0,r.jsx)("span",{className:"text-text-tertiary","aria-hidden":"true",children:"/"}),(0,r.jsx)("span",{className:"text-foreground font-semibold",children:e("Endpoint Settings")})]}),(0,r.jsx)($,{}),(0,r.jsx)(A.B,{}),(0,r.jsx)(k,{}),(0,r.jsx)(p,{})]})})}),(0,r.jsx)(w.i,{})]})}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.