### Get Started Source: https://docs.z.ai/guides/agents/slide Quick start guides, overview, and pricing information to help you begin with the Z.AI platform. ```APIDOC ## Overview ### Description Provides a general introduction to the Z.AI platform and its capabilities. ### Endpoint N/A ### Method N/A ## Quick Start ### Description Guides you through the initial steps to get started with the Z.AI platform. ### Endpoint N/A ### Method N/A ## Pricing ### Description Information on the pricing structure for Z.AI services and models. ### Endpoint N/A ### Method N/A ``` -------------------------------- ### Download Claude Code Setup Script Source: https://docs.z.ai/devpack/quick-start This command downloads the recommended shell script for setting up Claude Code environment variables. It's a convenient option for first-time users. Ensure you have curl installed and execute this in your Mac OS terminal or Windows cmd. ```shell curl -O "http://bigmodel-us3-prod-marketplace.cn-wlcb.ufileos.com/1753683755292-30b3431f487b4cc1863e57a81d78e289.sh?ufileattname=claude_code_prod_zai.sh" ``` -------------------------------- ### Bash Command for Node.js Installation (Example) Source: https://nodejs.org/en/download This section provides an example of how Node.js might be installed using bash, often presented as a copy-paste command. It's a common way for users to quickly install software on Linux or macOS systems. The exact command may vary depending on the specific installation method or version manager used. ```bash and their installation scripts are not maintained by the Node.js project. If you encounter any issues please visit **'s website** ``` -------------------------------- ### Install and Use Z.AI SDK for Python Source: https://context7_llms This section provides instructions for installing and using the Z.AI Python SDK to generate images. It includes commands for installing the SDK, verifying the installation, and a code example for making an API call. ```bash # Install latest version pip install zai-sdk # Or specify version pip install zai-sdk==0.0.4 ``` ```python import zai print(zai.__version__) ``` ```python from zai import ZaiClient client = ZaiClient(api_key="your-api-key") response = client.images.generations( model="cogView-4-250304", prompt="A cute little kitten sitting on a sunny windowsill, with the background of blue sky and white clouds.", ) print(response.data[0].url) ``` -------------------------------- ### Install goose CLI using curl (Linux/macOS/Windows) Source: https://block.github.io/goose/docs/quickstart This command downloads and executes a script to install the goose CLI. It's a cross-platform solution for installing the command-line interface of the goose agent. Ensure you have curl installed and necessary permissions. ```bash curl -fsSL https://github.com/block/goose/releases/download/stable/download_cli.sh | bash ``` -------------------------------- ### Install and Use Zai-SDK for Video Generation (Python) Source: https://context7_llms This section provides instructions for installing the zai-sdk Python package and demonstrates how to use it to generate videos from text prompts. It covers installation via pip and includes a code example for initializing the client and calling the video generation function with various parameters. ```bash # Install latest version pip install zai-sdk # Or specify version pip install zai-sdk==0.0.4 ``` ```python import zai print(zai.__version__) ``` ```python from zai import ZaiClient client = ZaiClient(api_key="your-api-key") response = client.videos.generations( model="viduq1-text", prompt="Peter Rabbit driving a car, wandering on the road, with a happy and joyful expression on his face.", style="general", duration=5, aspect_ratio="16:9", size="1920x1080", movement_amplitude="auto" ) print(response) ``` -------------------------------- ### Install and Use OpenAI Node.js SDK with Z.AI Source: https://context7_llms This guide details how to install the OpenAI Node.js SDK using npm or yarn. It then presents a usage example demonstrating how to instantiate the OpenAI client with your Z.AI API key and base URL, and make an asynchronous call to the chat completions endpoint. ```bash # Install or upgrade to latest version npm install openai # Or using yarn yarn add openai ``` ```javascript import OpenAI from "openai"; const client = new OpenAI({ apiKey: "your-Z.AI-api-key", baseURL: "https://api.z.ai/api/paas/v4/" }); async function main() { const completion = await client.chat.completions.create({ model: "glm-4.6", messages: [ { role: "system", content: "You are a helpful AI assistant." }, { role: "user", content: "Hello, please introduce yourself." } ] }); console.log(completion.choices[0].message.content); } main(); ``` -------------------------------- ### Install and Use Official Java SDK for Z.AI Source: https://context7_llms This guide explains how to add the Z.AI Java SDK to your project using Maven or Gradle. It then provides a Java code example for initializing the ZaiClient with an API key, constructing a chat completion request with model and messages, sending the request, and retrieving the content of the response. ```xml ai.z.openapi zai-sdk 0.0.4 ``` ```groovy implementation 'ai.z.openapi:zai-sdk:0.0.4' ``` ```java import ai.z.openapi.ZaiClient; import ai.z.openapi.service.model.*; import java.util.Arrays; public class QuickStart { public static void main(String[] args) { // Initialize client ZaiClient client = ZaiClient.builder() .apiKey("YOUR_API_KEY") .build(); // Create chat completion request ChatCompletionCreateParams request = ChatCompletionCreateParams.builder() .model("glm-4.6") .messages(Arrays.asList( ChatMessage.builder() .role(ChatMessageRole.USER.value()) .content("Hello, who are you?") .build() )) .stream(false) .build(); // Send request ChatCompletionResponse response = client.chat().createChatCompletion(request); // Get response System.out.println(response.getData().getChoices().get(0).getMessage().getContent()); } } ``` -------------------------------- ### Start Goose Session in Web UI via CLI Source: https://block.github.io/goose/docs/quickstart Starts a new Goose session and automatically opens the web-based chat interface in the browser. This provides a graphical way to interact with Goose. ```bash goose web --open ``` -------------------------------- ### Automated Task Management Examples Source: https://docs.z.ai/devpack/quick-start This snippet showcases automated task management capabilities. It includes examples of fixing code style issues, resolving ESLint errors, and generating documentation. These features aim to streamline development workflows. ```text # Auto-fix code style issues Fix all ESLint errors # Auto-generate documentation Generate detailed documentation for this API ``` -------------------------------- ### Install and Use Official Python SDK for Z.AI Source: https://context7_llms This section details how to install the Z.AI Python SDK using pip, with options to install the latest version or a specific version. It also provides a code example to verify the installed SDK version and a usage example demonstrating how to initialize the ZaiClient, create a chat completion request, and print the response content. ```bash # Install latest version pip install zai-sdk # Or specify version pip install zai-sdk==0.0.3.3 ``` ```python import zai print(zai.__version__) ``` ```python from zai import ZaiClient # Initialize client client = ZaiClient(api_key="YOUR_API_KEY") # Create chat completion request response = client.chat.completions.create( model="glm-4.6", messages=[ { "role": "system", "content": "You are a helpful AI assistant." }, { "role": "user", "content": "Hello, please introduce yourself." } ] ) # Get response print(response.choices[0].message.content) ``` -------------------------------- ### Install Zai SDK with Pip Source: https://docs.z.ai/guides/video/vidu-q1 This snippet demonstrates how to install the Zai SDK using pip. It shows the basic pip install command and an example of installing a specific version. This is a common method for package management in Python environments. ```python pip install zai-sdk # Or specify version pip install zai-sdk==0.0.4 ``` -------------------------------- ### Natural Language Programming Example (Shell) Source: https://docs.z.ai/devpack/quick-start This example demonstrates how to initiate natural language programming commands within a Claude Code environment. It uses a comment to describe the intent and then proceeds with a placeholder command. This snippet is intended as a starting point for using natural language to interact with code generation or execution tools. ```shellscript # Using Natural Language Commands in Claude Code Please create ``` -------------------------------- ### Code Repository Q&A Example Source: https://docs.z.ai/devpack/quick-start This snippet demonstrates how to ask questions about a team's codebase. The AI analyzes the code to provide detailed explanations, including authentication processes and relevant files. This functionality helps maintain a holistic understanding of the project. ```text Q: How is user authentication implemented in this project? A: GLM-4.6 analyzes your codebase and provides detailed explanations of the authentication process and related files. ``` -------------------------------- ### Python: Install and Use OpenAI SDK for Z.AI Source: https://context7_llms This Python snippet covers installing the OpenAI SDK, verifying the installation, and provides an example of using the SDK to create a chat completion with a Z.AI model. It requires setting an API key and base URL. ```bash # Install or upgrade to latest version pip install --upgrade 'openai>=1.0' ``` ```python from openai import OpenAI client = OpenAI( api_key="your-Z.AI-api-key", base_url="https://api.z.ai/api/paas/v4/" ) completion = client.chat.completions.create( model="glm-4-32b-0414-128k", messages=[ {"role": "system", "content": "You are a smart and creative novelist"}, {"role": "user", "content": "Please write a short fairy tale story as a fairy tale master"} ] ) print(completion.choices[0].message.content) ``` -------------------------------- ### Install Claude Code using npm Source: https://docs.z.ai/devpack/quick-start This snippet demonstrates how to install the Claude Code tool globally using npm. It requires Node.js version 18 or later. After installation, users can run the 'claude' command to launch the interactive interface. ```bash # Open your terminal and install Claude Code npm install -g @anthropic-ai/claude-code # Create your working directory (e.g., `your-project`) and navigate to it using `cd` cd your-project # After installation, run `claude` to enter the Claude Code interactive interface claude ``` -------------------------------- ### Install and Use OpenAI Python SDK with Z.AI Source: https://context7_llms This section provides instructions for installing or upgrading the OpenAI Python SDK, which can be configured to work with the Z.AI API. It includes commands to verify the installation and a usage example that initializes the OpenAI client with your Z.AI API key and the correct base URL, then makes a chat completion request. ```bash # Install or upgrade to latest version pip install --upgrade 'openai>=1.0' ``` ```python python -c "import openai; print(openai.__version__)" ``` ```python from openai import OpenAI client = OpenAI( api_key="your-Z.AI-api-key", base_url="https://api.z.ai/api/paas/v4/" ) completion = client.chat.completions.create( model="glm-4.6", messages=[ {"role": "system", "content": "You are a smart and creative novelist"}, {"role": "user", "content": "Please write a short fairy tale story as a fairy tale master"} ] ) print(completion.choices[0].message.content) ``` -------------------------------- ### Start Goose Session via CLI Source: https://block.github.io/goose/docs/quickstart Initiates a new conversation session with Goose from the command line interface. This command is used after configuring LLM providers and setting up a project directory. ```bash goose session ``` -------------------------------- ### Java: Install and Basic/Streaming Chat Completion Source: https://context7_llms This Java snippet shows how to set up the Z.AI SDK using Maven or Gradle, and then perform basic and streaming chat completions. It requires the `zai-sdk` dependency and an API key for client initialization. The basic call prints the AI reply or error, while the streaming example is intended for further implementation. ```xml ai.z.openapi zai-sdk 0.0.6 ``` ```groovy implementation 'ai.z.openapi:zai-sdk:0.0.6' ``` ```java import ai.z.openapi.ZaiClient; import ai.z.openapi.service.model.ChatCompletionCreateParams; import ai.z.openapi.service.model.ChatCompletionResponse; import ai.z.openapi.service.model.ChatMessage; import ai.z.openapi.service.model.ChatMessageRole; import java.util.Arrays; public class BasicChat { public static void main(String[] args) { // Initialize the client ZaiClient client = ZaiClient.builder() .apiKey("your-api-key") .build(); // Create a chat completion request ChatCompletionCreateParams request = ChatCompletionCreateParams.builder() .model("glm-4-32b-0414-128k") .messages(Arrays.asList( ChatMessage.builder() .role(ChatMessageRole.USER.value()) .content("As a marketing expert, please create an attractive slogan for my product.") .build() )) .build(); // Send request ChatCompletionResponse response = client.chat().createChatCompletion(request); // Get the response if (response.isSuccess()) { Object reply = response.getData().getChoices().get(0).getMessage().getContent(); System.out.println("AI Reply: " + reply); } else { System.err.println("Error: " + response.getMsg()); } } } ``` ```java import ai.z.openapi.ZaiClient; import ai.z.openapi.service.model.ChatCompletionCreateParams; import ai.z.openapi.service.model.ChatCompletionResponse; import ai.z.openapi.service.model.ChatMessage; import ai.z.openapi.service.model.ChatMessageRole; import ai.z.openapi.service.model.Delta; import java.util.Arrays; public class StreamingChat { ``` -------------------------------- ### Natural Language Command Example (Shell Script) Source: https://docs.z.ai/devpack/quick-start This example shows a natural language command for initiating code generation within a Claude environment. It is a placeholder comment indicating the intent to use natural language for programming tasks. ```shellscript # Using Natural Language Commands in Claude Code Please create a React ``` -------------------------------- ### Configure Goose Extension via CLI Source: https://block.github.io/goose/docs/quickstart Opens the Goose configuration menu to add or manage extensions. This example demonstrates adding the 'Computer Controller' built-in extension with a specified timeout. ```bash goose configure ``` -------------------------------- ### Install and Use Z.AI Python SDK for Chat Completions Source: https://context7_llms This code demonstrates how to install and use the official Z.AI Python SDK to make chat completion API calls. It covers SDK installation, version verification, and a basic usage example for initializing the client and creating a chat completion request. Replace 'YOUR_API_KEY' with your actual Z.AI API key. ```bash # Install latest version pip install zai-sdk # Or specify version pip install zai-sdk==0.0.4 ``` ```python import zai print(zai.__version__) from zai import ZaiClient # Initialize client client = ZaiClient(api_key="YOUR_API_KEY") # Create chat completion request response = client.chat.completions.create( model="glm-4.6", messages=[ { "role": "system", "content": "You are a helpful AI assistant." }, { "role": "user", "content": "Hello, please introduce yourself." } ] ) # Get response print(response.choices[0].message.content) ``` -------------------------------- ### JavaScript: AI Smart Code Completion Example Source: https://docs.z.ai/devpack/quick-start Illustrates the smart code completion feature, where an AI assists in writing JavaScript code. The example shows how the AI can auto-complete function implementations based on the function signature and context, thereby reducing manual effort and enhancing development speed. ```javascript // Type function name, GLM-4.6 auto-completes implementation function calculateTotal(items) { // GLM-4.6 automatically generates complete function implementation } ``` -------------------------------- ### Python HTTP Client Example Source: https://docs.z.ai/guides/develop/python/introduction Demonstrates how to instantiate and use an HTTP client for interacting with AI services. This example shows the basic setup for making requests. ```python from zai import ZaiClient import json # ... (other code) client = ZaiClient( api_key="YOUR_API_KEY", base_url="https://api.zaai.dev" ) response = client.chat.completions.create( model="claude-3-opus-20240229", messages=[ {"role": "user", "content": "Who won the world series in 2020?"}, {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."} ], temperature=0, stream=False, tool_choice=[ { "type": "function", "function": { "name": "get_weather", "description": "Get weather information", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA" }, "date": { "type": "string", "description": "The date to get the weather for, e.g. 2023-01-01" } }, "required": ["location", "date"] } } } ] ) print(response.choices[0].message.tool_calls) ``` -------------------------------- ### Java Usage Example for ZaiClient Source: https://docs.z.ai/api-reference/introduction Demonstrates how to import and instantiate the ZaiClient in a Java application. This example shows basic setup and assumes necessary imports are handled. ```java import ai.z.openapi.ZaiClient; import ai.z.openapi.service.model.*; public class ExampleUsage { public static void main(String[] args) { // Example instantiation (replace with actual parameters if needed) ZaiClient client = new ZaiClient(); // Further usage of the client would go here... System.out.println("ZaiClient initialized."); } } ``` -------------------------------- ### Natural Language Programming Example with Claude Code Source: https://docs.z.ai/devpack/quick-start Demonstrates how to use natural language to request code generation from Claude Code. This example asks for a React component with a user login form. GLM-4.6 will then generate the code, including validation and styling. ```natural_language # Using Natural Language Commands in Claude Code Please create a React component containing a user login form ``` -------------------------------- ### Install and Verify Z.AI Python SDK Source: https://context7_llms This snippet covers the installation of the Z.AI Python SDK using pip. It shows how to install the latest version or a specific version. It also includes a basic command to verify the installation by printing the installed SDK version. ```bash # Install the latest version pip install zai-sdk # Or specify a version pip install zai-sdk==0.0.4 ``` ```python import zai print(zai.__version__) ``` -------------------------------- ### Smart Code Completion Example in Claude Code Source: https://docs.z.ai/devpack/quick-start Illustrates Claude Code's smart code completion feature. When you start typing a function name, GLM-4.6 can automatically generate the complete function implementation based on the context provided. ```javascript // Type function name, GLM-4.6 auto-completes implementation function calculateTotal(items) { // GLM-4.6 automatically generates complete function implementation } ``` -------------------------------- ### Python SDK: Basic Conversation Example Source: https://docs.z.ai/guides/develop/python/introduction Demonstrates how to initiate a basic conversation with the Z.AI API using the Python SDK. This involves creating a client, setting up a message, and receiving a response. Ensure you have your API key and have installed the SDK. ```python from z_ai_sdk.client import ZaiClient # Initialize the client with your API key client = ZaiClient("YOUR_API_KEY") # Define the conversation message message = { "role": "user", "content": "Hello, tell me a short story." } # Send the message and get a response response = client.chat.completions.create( model="model-name", # Replace with the desired model messages=[message] ) # Print the response content print(response.choices[0].message.content) ``` -------------------------------- ### Install and Use Z.AI SDK for Java Source: https://context7_llms This section details how to set up and utilize the Z.AI Java SDK for image generation. It includes Maven and Gradle dependency configurations, along with a Java code example for an API call. ```xml ai.z.openapi zai-sdk 0.0.6 ``` ```groovy implementation 'ai.z.openapi:zai-sdk:0.0.6' ``` ```java import ai.z.openapi.ZaiClient; import ai.z.openapi.core.Constants; import ai.z.openapi.service.image.CreateImageRequest; import ai.z.openapi.service.image.ImageResponse; public class CogView4Example { public static void main(String[] args) { ZaiClient client = ZaiClient.builder().apiKey("YOUR_API_KEY").build(); // Create image generation request CreateImageRequest request = CreateImageRequest.builder() .model(Constants.ModelCogView4250304) .prompt("A cute little kitten sitting on a sunny windowsill, with the background of blue sky and white clouds.") .size("1024x1024") .build(); ImageResponse response = client.images().createImage(request); System.out.println(response.getData()); } } ``` -------------------------------- ### Generate Video from Image using Z.AI SDK (Python) Source: https://context7_llms This Python code snippet shows how to generate a video from an image using the Z.AI SDK. It includes instructions for installing the SDK (`pip install zai-sdk`) and a code example for initializing the client and making the video generation request. The `zai-sdk` library is required. ```bash # Install latest version pip install zai-sdk # Or specify version pip install zai-sdk==0.0.4 ``` ```python import zai print(zai.__version__) ``` ```python from zai import ZaiClient # Initialize the client, please replace your-api-key with your own APIKey. client = ZaiClient(api_key="your-api-key") # Video generation example from images. response = client.videos.generations( model="vidu2-image", image_url="https://example.com/path/to/your/image.jpg", prompt="Peter Rabbit is driving a small car, cruising on the road, with a face full of happiness and joy.", duration=4, size="1280x720", movement_amplitude="auto" ) # Print the response result. print(response) ``` -------------------------------- ### Install OpenCode CLI (Shell Script) Source: https://docs.z.ai/devpack/tool/opencode Installs the OpenCode CLI using a curl command to download and execute an installation script. This is the simplest method for getting started. ```shell curl -fsSL https://opencode.ai/install | bash ``` -------------------------------- ### Guides Source: https://docs.z.ai/devpack/tool/goose Guides covering getting started, SDKs, language models, visual language models, image generation, video generation, tools, and agents. ```APIDOC ## Guides ### Get Started - Quick Start - Overview - Pricing ### SDKs Guide - HTTP Introduction - Python Introduction - Java Introduction - OpenAI Python - Langchain Introduction ### Language Models - GLM-4.6 - GLM-4.5 - GLM-4-32b-0414-128k ### Visual Language Models - GLM-4.5v ### Image Generation Models - CogView-4 ### Video Generation Models - CogVideoX-3 - Vidu-Q1 - Vidu2 ### Tools - Web Search - Stream Tool ### Agents - Slide - Translation - Video Template ``` -------------------------------- ### Download Link for Node.js Installer Package Source: https://nodejs.org/en/download This is a direct download link for an installer package for Node.js. Installers typically provide a more guided setup process for users on Windows, macOS, or other operating systems. This link is for the v22.20.0 (LTS) version. ```html [N/A Installer (.gz)](https://nodejs.org/dist/v22.20.0/node-v22.20.0.tar.gz) ``` -------------------------------- ### Install Claude Code with Cursor IDE Guidance Source: https://docs.z.ai/devpack/tool/claude This command can be used within the Cursor IDE to initiate a guided installation of Claude Code. Cursor will assist the user through the setup process. ```shellscript https://docs.anthropic.com/en/docs/claude-code/overview" Help me install Claude Code ``` -------------------------------- ### Install Claude Code via Cursor Guided Method Source: https://docs.z.ai/devpack/tool/claude This code snippet demonstrates how to initiate the installation of Claude Code using a command within the Cursor IDE. Cursor will then guide the user through the installation process. Ensure you have Cursor installed to use this method. ```shellscript https://docs.anthropic.com/en/docs/claude-code/overview Help me install Claude Code ``` -------------------------------- ### Python: Install, Verify, and Chat Completion Source: https://context7_llms This Python snippet demonstrates how to install and verify the Z.AI SDK, and then perform basic and streaming chat completions. It requires the `zai-sdk` package and an API key for client initialization. The basic call prints the response content, while the streaming call iterates through chunks. ```bash # Install latest version pip install zai-sdk # Or specify version pip install zai-sdk==0.0.4 ``` ```python import zai print(zai.__version__) ``` ```python from zai import ZaiClient # Initialize the client client = ZaiClient(api_key="your-api-key") # Create a chat completion request response = client.chat.completions.create( model="glm-4-32b-0414-128k", messages=[ {"role": "user", "content": "As a marketing expert, please create an attractive slogan for my product."} ] ) # Get the response print(response.choices[0].message.content) ``` ```python from zai import ZaiClient # Initialize the client client = ZaiClient(api_key="your-api-key") # Create a streaming chat completion request stream = client.chat.completions.create( model="glm-4-32b-0414-128k", messages=[ {"role": "user", "content": "As a marketing expert, please create an attractive slogan for my product."} ], stream=True ) # Process streaming response for chunk in stream: if chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="") ``` -------------------------------- ### SvelteKit Application Initialization (JavaScript) Source: https://chat.z.ai/ This snippet initializes the SvelteKit application. It retrieves configuration for the base path and assets from `__sveltekit_1sg0e3b`. It then dynamically imports the necessary SvelteKit entry points (`start.js` and `app.js`) and starts the application by passing these modules and the current script's parent element to `kit.start()`. ```javascript var __sveltekit_1sg0e3b = { base: "", assets: "https://z-cdn.chatglm.cn/z-ai/frontend/prod-fe-1.0.98" }; const element = document.currentScript.parentElement; Promise.all([ import("https://z-cdn.chatglm.cn/z-ai/frontend/prod-fe-1.0.98/_app/immutable/entry/start.DWvKlf2V.js"), import("https://z-cdn.chatglm.cn/z-ai/frontend/prod-fe-1.0.98/_app/immutable/entry/app.DsmVHQrd.js") ]).then(([kit, app]) => { kit.start(app, element); }); ``` -------------------------------- ### Zai SDK Usage Example: Client Initialization Source: https://docs.z.ai/api-reference/introduction Demonstrates how to initialize the ZaiClient with an API key. This is a foundational step for interacting with Zai services. Ensure you replace 'api_key' with your actual Zai API key. ```python from zai import ZaiClient # Initialize client client = ZaiClient( api_key="api_key" ``` -------------------------------- ### Install OpenCode CLI Source: https://context7_llms Provides two methods for installing the OpenCode CLI: using a curl script for a quick setup or via npm for global installation. This CLI tool is essential for integrating Z.AI's GLM models into your development workflow. ```bash curl -fsSL https://opencode.ai/install | bash ``` ```bash npm install -g opencode-ai ``` -------------------------------- ### OpenAI Node.js SDK Usage Example Source: https://docs.z.ai/api-reference/introduction A basic JavaScript example demonstrating how to import and use the OpenAI Node.js SDK. This snippet shows how to initialize the client and make a call. ```javascript import OpenAI from "openai"; const client = new OpenAI ``` -------------------------------- ### Create Z.AI Client with Basic Configuration Source: https://context7_llms Initializes the Z.AI OpenAI client using a provided API key and the Z.AI base URL. This is a fundamental step before making any API calls. ```python from openai import OpenAI # Create Z.AI client client = OpenAI( api_key="your-Z.AI-api-key", base_url="https://api.z.ai/api/paas/v4/" ) ``` -------------------------------- ### OpenAI Java Client Usage Example Source: https://docs.z.ai/api-reference/introduction A basic Java usage example demonstrating how to instantiate the OpenAIClient and OpenAIOkHttpClient. This code can be used as a starting point for interacting with the OpenAI API in a Java application. ```java import com.openai.client.OpenAIClient; import com.openai.client.okhttp.OpenAIOkHttpClient; ``` -------------------------------- ### Swift: Setup and Run System Monitor Application Source: https://huggingface.co/datasets/zai-org/CC-Bench-trajectories This Swift code initializes and runs a macOS application designed to monitor system resources. It sets up the main application delegate, creates and configures the application window, and initiates the system monitoring process. The `SystemMonitor` class is expected to be defined elsewhere and provides the actual metric collection. ```swift import AppKit class AppDelegate: NSObject, NSApplicationDelegate { var window: NSWindow? var systemMonitor: SystemMonitor? var metricsView: MetricsView? func applicationDidFinishLaunching(_ aNotification: Notification) { setupWindow() setupMonitoring() } func applicationWillTerminate(_ aNotification: Notification) { systemMonitor?.stopMonitoring() } private func setupWindow() { let window = NSWindow( contentRect: NSRect(x: 0, y: 0, width: 400, height: 250), styleMask: [.titled, .closable, .miniaturizable, .resizable], backing: .buffered, defer: false ) window.title = "System Monitor" window.center() let metricsView = MetricsView(frame: window.contentView!.bounds) metricsView.autoresizingMask = [.width, .height] window.contentView = metricsView self.window = window self.metricsView = metricsView window.makeKeyAndOrderFront(nil) } private func setupMonitoring() { let monitor = SystemMonitor() monitor.onMetricsUpdate = { [weak self] metrics in self?.metricsView?.updateMetrics(metrics) self?.updateWindowTitle(with: metrics) } monitor.startMonitoring() self.systemMonitor = monitor } private func updateWindowTitle(with metrics: SystemMetrics) { DispatchQueue.main.async { let title = String(format: "System Monitor - CPU: %.1f%% | Memory: %.1f%% | Disk: %.1f%%", metrics.cpuUsage, metrics.memoryUsage, metrics.diskUsage) self.window?.title = title } } } let app = NSApplication.shared let delegate = AppDelegate() app.delegate = delegate app.run() ``` -------------------------------- ### Initialize OpenCode for a Project Source: https://opencode.ai/docs Commands to navigate to a project directory and initialize OpenCode. This process analyzes the project and generates an AGENTS.md file, which helps OpenCode understand the project structure. ```shell cd /path/to/project opencode /init ``` -------------------------------- ### Call Example: Create Image Request with ZaiClient (Java) Source: https://docs.z.ai/guides/image/cogview-4 This Java code example demonstrates how to use the ZaiClient to create an image. It includes necessary imports for ZaiClient, Constants, CreateImageRequest, and ImageResponse. This serves as a starting point for image generation tasks. ```java import ai.z.openapi.ZaiClient; import ai.z.openapi.core.Constants; import ai.z.openapi.service.image.CreateImageRequest; import ai.z.openapi.service.image.ImageResponse; public class CogView ``` -------------------------------- ### Python SDK Integration Source: https://context7_llms Guides on installing and using the official Python SDK for interacting with the GLM-4.6 model, covering basic and streaming chat completions. ```APIDOC ## Python SDK for Chat Completions ### Installation ```bash # Install latest version pip install zai-sdk # Or specify version pip install zai-sdk==0.0.4 ``` ### Verification ```python import zai print(zai.__version__) ``` ### Basic Call ```python from zai import ZaiClient client = ZaiClient(api_key="your-api-key") # Your API Key response = client.chat.completions.create( model="glm-4.6", messages=[ {"role": "user", "content": "As a marketing expert, please create an attractive slogan for my product."}, {"role": "assistant", "content": "Sure, to craft a compelling slogan, please tell me more about your product."}, {"role": "user", "content": "Z.AI Open Platform"} ], thinking={ "type": "enabled", }, max_tokens=4096, temperature=1.0 ) # Get complete response print(response.choices[0].message) ``` ### Streaming Call ```python from zai import ZaiClient client = ZaiClient(api_key="your-api-key") # Your API Key response = client.chat.completions.create( model="glm-4.6", messages=[ {"role": "user", "content": "As a marketing expert, please create an attractive slogan for my product."}, {"role": "assistant", "content": "Sure, to craft a compelling slogan, please tell me more about your product."}, {"role": "user", "content": "Z.AI Open Platform"} ], thinking={ "type": "enabled", # Optional: "disabled" or "enabled", default is "enabled" }, stream=True, max_tokens=4096, temperature=0.6 ) # Stream response for chunk in response: if chunk.choices[0].delta.reasoning_content: print(chunk.choices[0].delta.reasoning_content, end='', flush=True) if chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end='', flush=True) ``` ``` -------------------------------- ### Basic Z.AI LLM API Usage Example (Python) Source: https://docs.z.ai/api-reference/introduction This Python code example shows how to initialize the Z.AI OpenAI client with an API key and base URL, and then demonstrates a basic API call. Ensure you replace 'your-Z.AI-api-key' with your actual API key. ```python from openai import OpenAI client = OpenAI( api_key="your-Z.AI-api-key", base_url="https://api.z.ai/api/paas/v4/" ) completion = ``` -------------------------------- ### Install Java SDK with Maven Dependency Source: https://docs.z.ai/guides/image/cogview-4 This section provides instructions for installing the Java SDK using Maven. It includes the necessary XML configuration for the Maven dependency, specifying the groupId, artifactId, and version. This setup is crucial for integrating the AI LLM functionality into a Java project. ```xml ai.z.openapi openapi 1.0.0 ``` -------------------------------- ### Launch and Interact with OpenCode Source: https://context7_llms These commands show how to launch the OpenCode application and interact with it, including selecting models and managing conversation sharing. The `/models` command lists available AI models, while `/share` and `/unshare` control conversation visibility. ```bash $ opencode ``` ```bash /models ``` ```bash /share ``` ```bash /unshare ``` -------------------------------- ### VS Code Installation Link for MCP SQLite Server Source: https://github.com/modelcontextprotocol/servers-archived/tree/main/src/sqlite This is a pre-configured URL for installing the MCP SQLite server extension directly into VS Code or VS Code Insiders. It prompts the user for the SQLite database path and sets up the server configuration. This allows for a streamlined setup process within the VS Code environment. ```html Install with UV in VS Code ``` -------------------------------- ### Generate Video from Start and End Frames using Python SDK Source: https://context7_llms This snippet demonstrates video generation using start and end frames with the Zai Python SDK. After installing the SDK, initialize the client and use the `generations` method, providing a list containing the URLs for the first and last frames, along with the prompt and other video parameters. ```bash # Install latest version pip install zai-sdk # Or specify version pip install zai-sdk==0.0.4 ``` ```python import zai print(zai.__version__) ``` ```python from zai import ZaiClient client = ZaiClient(api_key="your-api-key") # Define URLs for first frame and last frame sample_first_frame = "https://gd-hbimg.huaban.com/ccee58d77afe8f5e17a572246b1994f7e027657fe9e6-qD66In_fw1200webp" sample_last_frame = "https://gd-hbimg.huaban.com/cc2601d568a72d18d90b2cc7f1065b16b2d693f7fa3f7-hDAwNq_fw1200webp" # Video generation request (first and last frame mode) response = client.videos.generations( model="viduq1-start-end", image_url=[sample_first_frame, sample_last_frame], # The first and last frame images prompt="Peter Rabbit driving a car, wandering on the road, with a happy and joyful expression on his face.", duration=5, #Video duration (seconds) size="1920x1080", # Video resolution movement_amplitude="auto", # Movement amplitude ) # Print the response result print(response) ``` -------------------------------- ### Initialize ZaiClient and Create Chat Completion (Python) Source: https://context7_llms This snippet demonstrates how to initialize the ZaiClient with an API key and create a basic chat completion. It shows how to send a system message and a user message, and how to stream the response, printing each content chunk as it arrives. Ensure you have the 'zai' library installed. ```python from zai import ZaiClient # Initialize client client = ZaiClient(api_key="your-api-key") # Create chat completion response = client.chat.completions.create( model='glm-4.6', messages=[ {'role': 'system', 'content': 'You are an AI writer.'}, {'role': 'user', 'content': 'Tell a story about AI.'}, ], stream=True, ) for chunk in response: if chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end='') ``` -------------------------------- ### Initialize ZaiClient Directly (Python) Source: https://docs.z.ai/guides/develop/python/introduction This code example demonstrates how to initialize the ZaiClient by directly passing the API key as a string argument. This approach is suitable for development or when the API key is managed through configuration files. It requires importing the ZaiClient from the 'zai' library. ```python from zai import ZaiClient, ZaiClient # Set API Key directly client = ZaiClient(api_key="your_api_key_here") ``` -------------------------------- ### Resume Goose Session via CLI Source: https://block.github.io/goose/docs/quickstart Resumes the last active Goose session from the command line. This is useful for continuing a previous conversation without starting a new one. ```bash goose session -r ``` -------------------------------- ### Python SDK: Installation using pip Source: https://docs.z.ai/guides/develop/python/introduction Provides the command to install the Z.AI Python SDK using pip, the standard package installer for Python. This is the recommended method for integrating the SDK into your projects. ```bash pip install z-ai-sdk ``` -------------------------------- ### Manage Node.js with Docker Source: https://nodejs.org/en/download Pulls a specific Node.js Docker image and starts an interactive shell session within a container. Refer to Docker's official documentation for OS-specific installation. ```bash docker pull node:${props.release.major}-${props.release.major >= 4 ? 'alpine' : 'slim'}\n ``` ```bash docker run -it --rm --entrypoint sh node:${props.release.major}-${props.release.major >= 4 ? 'alpine' : 'slim'}\n ``` -------------------------------- ### Install Zai SDK using Pip Source: https://docs.z.ai/guides/video/vidu-q1 This command installs the Zai SDK and specifies a version. Ensure you have pip installed and accessible in your environment. This is the primary method for acquiring the SDK. ```bash # Or specify version pip install zai-sdk==0.0.4 ``` -------------------------------- ### JavaScript Smart Code Completion Example Source: https://docs.z.ai/devpack/quick-start This JavaScript snippet illustrates the smart code completion feature. The AI assists by automatically generating the implementation of a function based on its name and signature, significantly reducing manual coding effort and improving development speed. It shows how to initiate the process by typing the function name. ```javascript // Type function name, GLM-4.6 auto-completes implementation function calculateTotal(items) { // GLM-4.6 automatically generates complete function implementation ``` -------------------------------- ### Python SDK: Install and Verify Z.AI SDK Source: https://context7_llms Instructions for installing the Z.AI Python SDK using pip, including options for installing the latest version or a specific version. It also includes a code snippet to verify the installation by printing the SDK version. ```bash # Install latest version pip install zai-sdk # Or specify version pip install zai-sdk==0.0.4 ``` ```python import zai print(zai.__version__) ```