### OpenAI Compatible API Usage Source: https://www.maizitech.xyz This example demonstrates how to use the MaiziAI API with Python, leveraging the OpenAI client library. It shows how to perform AI chat completions and generate images. ```APIDOC ## OpenAI Compatible API MaiziAI offers an OpenAI-compatible API, allowing you to integrate AI services with minimal code changes. You can use standard OpenAI client libraries by configuring the `api_key` and `base_url`. ### Python Example ```python from openai import OpenAI client = OpenAI( api_key="sk-your-api-key", base_url="https://your-domain/v1" ) # AI Chat response = client.chat.completions.create( model="claude-sonnet-4-6", messages=[{"role": "user", "content": "Hello"}] ) print(response.choices[0].message.content) # Generate image image = client.images.generate( model="gpt-image-2", prompt="A cute cat playing the piano", size="1024x1024", n=1 ) print(image.data[0].url) ``` ### Parameters - **api_key**: Your unique API key obtained from the MaiziAI console. - **base_url**: The base URL provided by MaiziAI for API requests (e.g., `https://your-domain/v1`). ### Models MaiziAI supports various models for chat and image generation. Refer to the pricing section for available models and their specific capabilities. - **Chat Models**: `claude-sonnet-4-6`, `claude-opus-4-7`, etc. - **Image Models**: `gpt-image-2`, `nano-banana-standard`, etc. ### Request Body (Chat Completions) - **model** (string) - Required - The ID of the model to use for chat completion. - **messages** (array) - Required - A list of messages comprising the conversation so far. - **role** (string) - Required - The role of the author of a message (`system`, `user`, or `assistant`). - **content** (string) - Required - The content of the message. ### Request Body (Image Generation) - **model** (string) - Required - The ID of the model to use for image generation. - **prompt** (string) - Required - A text description of the desired image(s). - **size** (string) - Optional - The size of the generated images (e.g., `1024x1024`). - **n** (integer) - Optional - The number of images to generate. ### Response (Chat Completions) - **choices** (array) - Contains the generated chat completion(s). - **message** (object) - **content** (string) - The generated response from the model. ### Response (Image Generation) - **data** (array) - Contains the generated image(s). - **url** (string) - The URL of the generated image. ``` -------------------------------- ### OpenAI Compatible API Integration with Python Source: https://www.maizitech.xyz This snippet shows how to use the OpenAI Python client to interact with MaiziAI's services. Ensure you have the 'openai' library installed and replace 'sk-your-api-key' and 'https://your-domain/v1' with your actual API key and base URL. ```python from openai import OpenAI client = OpenAI( api_key="sk-your-api-key", base_url="https://your-domain/v1" ) # AI Chat response = client.chat.completions.create( model="claude-sonnet-4-6", messages=[{"role": "user", "content": "Hello"}] ) print(response.choices[0].message.content) # Generate image image = client.images.generate( model="gpt-image-2", prompt="A cute cat playing the piano", size="1024x1024", n=1 ) print(image.data[0].url) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.