Communitygithub.com

evalix098/tiktoklive

从应用服务器代码调用 xAI API(Grok),使用注入的 XAI_API_KEY 实现聊天/LLM 功能、图像和视频生成(Imagine)以及语音(文本转语音)。当应用需要任何“AI”、“助手”、“聊天机器人”、“Grok”功能、运行时图像/视频生成或语音时触发。

tiktoklive 是什么?

该技能为应用集成了 xAI API(Grok),允许开发者在服务器端代码中直接调用 xAI 的全套 AI 能力,包括最新的 Grok 聊天模型(grok-4.5)、图像生成(Imagine)、视频生成以及文本转语音。它通过平台注入的 `XAI_API_KEY` 环境变量工作,开发者无需自行管理密钥。该 API 完全兼容 OpenAI 格式(`https://api.x.ai/v1`),因此可以使用任何 OpenAI 风格的客户端进行调用。技能文档强调了开发者必须负责任地使用资源,因为密钥属于应用所有者,所有调用(包括来自匿名访客的)都会消耗其配额和积分。文档提供了详细的代码示例和最佳实践,包括如何安全地在服务器函数中发起请求、如何调用图像/视频/语音端点,以及如何避免浪费性调用。

兼容平台~Claude Code✓Codex CLI~Cursor
npx skills add https://github.com/evalix098/tiktoklive/tree/HEAD/.grok/skills/xai-api

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

xAI API (Grok)

当环境中存在 XAI_API_KEY 时,该应用拥有真正的 xAI API 访问权限——请将其用于 AI 功能,而不是模拟响应或使用其他提供商。同一变量在发布时会被注入到已部署的应用中,因此基于它构建的代码在预览和生产环境中将表现一致。

该密钥是应用所有者的个人密钥:每次调用都会消耗其配额和积分。 请谨慎使用——在将 AI 调用接入任何自动运行或对访客开放的功能之前,请先阅读负责任地使用资源。

该密钥可解锁完整的 API 接口,而不仅仅是聊天:

  • 聊天 / LLM — 最新模型:grok-4.5;除非用户另有要求,否则默认使用该模型。
  • Imagine(图像和视频) — 在应用运行时生成和编辑图像、生成视频。
  • 语音 — 具有表现力声音的文本转语音(以及转录功能)。
  • 官方文档:docs.x.ai — 端点、模型、参数、流式传输、工具使用。不要猜测 API 格式;请查阅文档。
  • 该 API 兼容 OpenAI(https://api.x.ai/v1),因此任何 OpenAI 风格的客户端都可以通过切换基础 URL 和密钥来使用。

环境变量 —— 请不要创建 .env 文件

变量位置用途
XAI_API_KEY服务端由平台注入(预览和部署)。切勿编写、硬编码或向用户询问。

该密钥仅限服务端使用:在 createServerFn 处理程序 / 服务端代码中使用 process.env.XAI_API_KEY 读取,切勿在客户端组件中使用,也切勿通过 VITE_ 前缀的变量或 API 响应暴露。

它可能缺失(逐步开放)。请优雅降级——检查其存在性并显示友好的“AI 功能不可用”状态,而不是崩溃:

const apiKey = process.env.XAI_API_KEY;
if (!apiKey) throw new Error("AI is not available in this environment");

调用 API(仅限服务端)

无需 SDK —— 从服务器函数中使用普通 fetch:

import { createServerFn } from "@tanstack/react-start";

export const askGrok = createServerFn({ method: "POST" })
  .validator((input: { prompt: string }) => input)
  .handler(async ({ data }) => {
    const apiKey = process.env.XAI_API_KEY;
    if (!apiKey) return { ok: false as const, error: "AI is not available" };

    const res = await fetch("https://api.x.ai/v1/chat/completions", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        Authorization: `Bearer ${apiKey}`,
      },
      body: JSON.stringify({
        model: "grok-4.5",
        messages: [{ role: "user", content: data.prompt }],
      }),
    });
    if (!res.ok) {
      return { ok: false as const, error: `xAI API error ${res.status}` };
    }
    const body = (await res.json()) as {
      choices: { message: { content: string } }[];
    };
    return { ok: true as const, text: body.choices[0]?.message.content ?? "" };
  });

对于流式传输、结构化输出、视觉或完整模型列表,请遵循 docs.x.ai —— 格式与 OpenAI 兼容。

Imagine —— 图像和视频生成(仅限服务端)

同一密钥可驱动应用中的运行时图像/视频功能(用户头像、场景艺术、生成内容)。区别于构建时的 imagine_text_to_image / imagine_image_to_image / imagine_image_to_video 工具(imagine-grok-build 技能):当正在运行的应用生成媒体时使用API,当您在构建时创建静态资源时使用这些工具。

// POST https://api.x.ai/v1/images/generations —— 与聊天相同的认证头
body: JSON.stringify({
  model: "grok-imagine-image-quality", // 或 "grok-imagine-image"(更便宜)
  prompt: data.prompt,
  // n(≤10),resolution("1k"|"2k"),response_format("url"|"b64_json")
})
// → body.data[0].url
  • 图像编辑:POST /v1/images/edits —— 自然语言编辑,最多 3 张参考图像。
  • 视频:grok-imagine-video 通过异步视频端点(启动,然后轮询返回的请求 ID;片段最长约 15 秒)。
  • 完整参数和示例:docs.x.ai → Imagine API。

语音 —— 文本转语音(仅限服务端)

POST https://api.x.ai/v1/tts 将文本转换为口语音频——旁白、无障碍、角色配音:

// 相同的 Authorization 头;返回音频字节(例如 MP3)
body: JSON.stringify({ text: data.text, voice_id: "eve" }) // eve = 默认声音

在 GET /v1/tts/voices 列出声音(支持自定义声音);转录(语音转文本)也可用。详情:docs.x.ai → Voice API。从您的服务器函数向客户端提供音频——切勿从浏览器调用 API(这将暴露密钥)。

负责任地使用资源

该密钥属于应用所有者(您为之构建的用户):每次调用——包括由已部署应用的匿名访客触发的调用——都会消耗其个人配额和积分。将其浪费在无意义的调用上会降低或破坏其密钥的所有其他用途。请注意使用:

  • 限制输出(max_tokens)并保持提示简短,特别是对于面向访客的功能。图像,尤其视频生成,每次调用的成本远高于聊天。
  • 切勿在循环中、每次按键或页面加载时调用 API —— 使调用由用户发起(按钮点击、表单提交)并去抖。
  • 缓存或持久化结果(参见 neon 技能),而不是为每个访客或每次渲染重新生成相同的内容。
  • 对高消耗流程加以限制——特别是媒体生成。在已有登录功能的应用上,将其置于 authMiddleware 之后(参见 auth 技能)。登录默认关闭,并且添加中间件而不实现它会破坏已部署的应用(AGENTS.md §0.5)——因此,在没有账户的应用上,请限制使用量:用户发起的调用、小限额、缓存结果。
  • 不要添加重试风暴:出现 API 错误时,反馈给用户;最多重试一次。

Individual skills in this repo

This repo contains 17 individual skills — each has its own dedicated page.

evalix098/tiktoklive

Add user accounts and sign-in to this TanStack Start app. Use when the app needs authentication, sign-in, user accounts, protected routes, or per-user data. Triggers on "auth", "login", "log in", "sign in", "sign up", "account", "users", "authentication", "protected", "who is logged in", "current user", "per-user".

evalix098/tiktoklive

Build browser games and interactive/canvas/3D experiences in this TanStack Start + React app. Use for any game, simulation, or WebGL/Canvas experience — 2D or 3D, single-player. Covers the game loop & timing, 3D orientation/camera conventions, collision, performance, assets, audio, save, game feel, and per-genre playbooks. For WASD / vehicle / flight **input signs and inverted A/D**, open the **`controls`** skill — do not rely on this file or racing-kart alone. Triggers on "game", "minecraft", "fps", "platformer", "racing", "tetris", "snake", "shooter", "3d", "three.js", "canvas", "voxel", "physics".

evalix098/tiktoklive

Player-facing input signs for browser games: WASD, vehicles, flight, FPS mouse-look, and the #1 failure mode (inverted A/D). Mandatory control self-tests and a tiny test interface so you can verify A turns left before shipping. Load for ANY game with movement, steering, flying, driving, tanks, boats, mechs, drones, planes, karts, third-person follow cams — not only racing. Triggers on "controls", "WASD", "inverted", "steer", "flight", "airplane", "kart", "vehicle", "yaw", "roll", "pitch", "mouse look", "A/D".

evalix098/tiktoklive

Design and build polished, non-generic UI for this TanStack Start + React + Tailwind v4 + shadcn/Radix app. Use whenever you create or restyle any interface surface — pages, landing pages, dashboards, forms, modals, nav, and game overlays (start screens, HUD, menus). Covers design tokens, layout, typography, color, spacing, motion, and the anti-"AI-slop" rules that keep output from looking generic. Triggers on "design", "UI", "make it look good", "polish", "landing page", "theme", "style", "redesign", "ugly", "clean up".

evalix098/tiktoklive

Deep guide for game ANIMATION assets: motion cycles, action keyframes, effect sequences, and animation sprite sheets — built around a video-first pipeline. In this app-builder sandbox, execute via the video2dsprite / generate2dsprite skills (magenta + scripts), not ad-hoc ffmpeg. Use whenever generating anything that moves: walk/run cycles, attacks, idles, FX, flags, fire, animation sheets. Complements game-asset-core.

evalix098/tiktoklive

Core discipline for ANY game-asset generation with Imagine tools: the engine-ready defaults users don't state, spec checklists, style anchoring, read-back verification, honest defect flagging. Use whenever generating any game art (sprites, sheets, animations, tiles, UI, FX) — then ALSO load the matching specialist skill: game-animation-frames for anything that moves, game-tilesets for tiles/terrain, game-character-consistency for recurring characters, game-ui-icons for UI and icons.

evalix098/tiktoklive

Deep guide for CHARACTER IDENTITY across images: turnarounds (front/side/ back), state and damage variants, palette swaps, equipment changes, and same-character-in-context sets. Use whenever generating character turnarounds, character sheets, variants of an existing sprite, or any same-subject multi-image set. Complements game-asset-core.

evalix098/tiktoklive

Deep guide for game TILE assets: seamless tileable textures, terrain transition tilesets, autotiles, and ground/platform tiles. Use whenever generating tileable textures, tilesets, terrain transitions, or seamless patterns. Complements game-asset-core.

evalix098/tiktoklive

Deep guide for game UI assets: buttons with interaction states, panels, bars, wordmark logos, and icon sets. Use whenever generating game UI elements, HUD assets, inventory icons, icon sets, buttons, or title logos. Complements game-asset-core.

evalix098/tiktoklive

Generate production-oriented 2D game maps with `imagine_text_to_image`: RPG/top-down maps, side-scroller parallax stages, tilemaps, layered raster maps, prop packs, collision zones, and walkable areas. Use when building browser games that need real map art (not pure code-drawn tiles), layered props, or map collision metadata. Triggers on "map", "level", "stage", "tilemap", "overworld", "dungeon", "side scroller background", "prop pack", "2D map".

evalix098/tiktoklive

Generate and postprocess 2D game sprites and animation sheets: pixel-art characters, NPCs, creatures, spells, projectiles, impacts, props, summons, and transparent PNG/GIF exports. Use when building browser games that need real sprite sheets (not code-drawn placeholders), matching a map art style, or producing magenta-background sheets for chroma-key cleanup. Triggers on "sprite", "sprite sheet", "animation sheet", "pixel art character", "walk cycle", "attack animation", "projectile sprite", "2D game asset".

evalix098/tiktoklive

How to use the Imagine tools in Grok Build: imagine_text_to_image, imagine_image_to_image, imagine_reference_to_image, imagine_text_to_video, imagine_image_to_video, imagine_reference_to_video, and render_file for chat previews. When to build a visual with code instead of generating it, prompt-craft, reference-first handling of real people, factual grounding, and asset-consistency. Load this whenever generating or editing an image or video is on the table. Tool-usage-driven, not triggered by a user merely mentioning images.

evalix098/tiktoklive

Peer-to-peer realtime multiplayer over WebRTC data channels: every user of the deployed app connects directly to every other user (full mesh), the server only brokers the handshake at /api/rtc. Lowest possible latency, zero per-message server cost. Use for 2-8 player co-op/casual realtime: shared cursors, drawing, party games, casual action. Triggers: p2p, peer to peer, webrtc, low latency multiplayer, direct connection.

evalix098/tiktoklive

Use Neon Postgres (the database) in this TanStack Start app. Use when the app needs to store or query data, persist state, or keep per-user data. Triggers on "database", "Postgres", "Neon", "save data", "store data", "persist", "tables", "SQL", "query", "migrations".

evalix098/tiktoklive

Share-link previews and app identity for apps on *.grok.me: the injector-owned og:image card, the SVG favicon, and PWA icons for installable apps. Use when scaffolding, renaming, or restyling the app — and for share / unfurl / OG / Twitter card questions. A custom 1200×630 card from the app's own art is the default — games of every kind (DOM board/word games included), whimsical apps, creative tools, and brand-forward pages; only plain utilities keep the placeholder. Always run the brand-asset pass as a `task` subagent and never wait for it. Triggers on "share", "rename", "app name", "OG", "Open Graph", "twitter card", "unfurl", "og:image", "og:type", "x:game:image", "x-banner", "link preview", "social card", "thumbnail", "preview image", "favicon", "app icon", "PWA", "manifest", "installable", "home screen", "SEO", "meta description".

evalix098/tiktoklive

Official Three.js API and TSL (Three.js Shading Language) reference for LLM code generation. Load when writing or debugging three.js / WebGL / WebGPU / custom materials / shaders / GLTF / advanced three APIs beyond basic game loop/controls. Prefer building-games for game correctness (loop, WASD, camera, orientation); use this skill for full API/TSL depth. Triggers on "three.js", "threejs", "WebGPU", "TSL", "NodeMaterial", "shader", "GLTF", "MeshStandard", "OrbitControls", "WebGLRenderer".

evalix098/tiktoklive

Grok Build only. Turn a 2D character still into denser animation sprites via imagine_text_to_image base → imagine_image_to_video (6s/10s run-in-place) → ffmpeg frames → magenta chroma-key → dense sampled strips/grids/GIFs. Use when the user wants video-to-sprite, smoother run/walk cycles, or denser intermediate poses. Prefer generate2dsprite for crisp production pixel sheets. Triggers on "video to sprite", "imagine_image_to_video sprite", "dense walk cycle", "smooth run animation from video".

相关技能