Z.AI Python SDK is the official Python development toolkit provided by Z.AI, offering Python developers convenient and efficient AI model integration solutions.
from zai import ZaiClientimport os# Read API Key from environment variableclient = ZaiClient(api_key=os.getenv("ZAI_API_KEY"))# Or use directly (if environment variable is set)client = ZaiClient()
from zai import ZaiClientclient = ZaiClient(api_key="your-api-key")response = client.chat.completions.create( model="glm-4.5", # Please fill in the model name you want to call messages=[ {"role": "user", "content": "As a marketing expert, please create an attractive slogan for my product"}, {"role": "assistant", "content": "Of course, to create an attractive slogan, please tell me some information about your product"}, {"role": "user", "content": "Z.AI Open Platform"}, {"role": "assistant", "content": "Ignite the future, Z.AI draws infinite possibilities, making innovation within reach!"}, {"role": "user", "content": "Create a more precise and attractive slogan"} ],)print(response.choices[0].message.content)
from zai import ZaiClientimport timeclient = ZaiClient(api_key="your-api-key")# Submit generation taskresponse = client.videos.generations( model="cogvideox-3", # Video generation model to use image_url=image_url, # Provided image URL or Base64 encoding prompt="Make the scene come alive", quality="speed", # Output mode: "quality" for quality priority, "speed" for speed priority with_audio=True, size="1920x1080", # Video resolution, supports up to 4K (e.g., "3840x2160") fps=30, # Frame rate, can be 30 or 60)print(response)# Get generation resulttime.sleep(60) # Wait for a while to ensure video generation is completeresult = client.videos.retrieve_videos_result(id=response.id)print(result)
This SDK is developed based on the latest API specifications from Z.AI, ensuring synchronization with platform features. It is recommended to regularly update to the latest version for the best experience.