### Example Prompts for ZenMux Features (Bash) Source: https://docs.zenmux.ai/best-practices/neovate-code Demonstrates example prompts for utilizing various AI features through Neovate and ZenMux. These examples cover code generation, migration, testing, and performance optimization, showcasing the practical applications of the integration. ```bash # Generate error handling "Add comprehensive error handling to the user authentication service" ``` ```bash # TypeScript migration "Convert this JavaScript module to TypeScript with proper type definitions" ``` ```bash # Testing "Create unit tests for the payment processing module with edge cases" ``` ```bash # Performance optimization "Optimize this SQL query for better performance with large datasets" ``` -------------------------------- ### Start Claude Code CLI in Project Directory Source: https://docs.zenmux.ai/best-practices/claude-code Navigates to your project directory and starts the Claude Code CLI. This assumes the configuration file is correctly set up. ```bash # Navigate to the project directory cd my-project # Start Claude Code claude ``` -------------------------------- ### Launch Neovate CLI (Bash) Source: https://docs.zenmux.ai/best-practices/neovate-code Launches the Neovate command-line interface. This can be done using the 'neovate' or 'neo' command after installation. This is the entry point for interacting with Neovate's features. ```bash neovate ``` ```bash neo ``` -------------------------------- ### Call ZenMux API Directly (Python - httpx) Source: https://docs.zenmux.ai/guide/quickstart This Python snippet demonstrates how to call the ZenMux API directly using the `httpx` library. It involves setting up authorization headers with your API key and constructing the request payload, including the model and messages. Ensure the `httpx` library is installed. ```python import httpx # Prepare request data api_key = "" headers = { "Authorization": f"Bearer {api_key}", } payload = { "model": "openai/gpt-5", "messages": [ { "role": "user", "content": "What is the meaning of life?" } ] } ``` -------------------------------- ### Install Neovate Code Package (Bash) Source: https://docs.zenmux.ai/best-practices/neovate-code Installs the Neovate Code package globally using npm. This command is essential for using Neovate's functionalities, including integration with ZenMux. Ensure Node.js and npm are installed on your system. ```bash npm install -g @neovate/code ``` -------------------------------- ### Example Final Response Source: https://docs.zenmux.ai/guide/advanced/tool-calls This is an example of a final response from the model after processing tool calls and generating a natural language answer. ```json "It's about 15°C in Paris and about 18°C in Bogotá. I’ve sent that email to Bob." ``` -------------------------------- ### API Call Example (Python) Source: https://docs.zenmux.ai/guide/advanced/structured-output Example of how to initialize the OpenAI client with the ZenMux base URL and API key for making API calls. ```APIDOC ## Python API Client Initialization ### Description This code snippet demonstrates how to initialize the OpenAI Python client to interact with the ZenMux API, including setting the base URL and API key. ### Method N/A (Client Initialization) ### Endpoint N/A ### Parameters N/A ### Request Example ```python from openai import OpenAI # 1. Initialize the OpenAI client client = OpenAI( # 2. Point the base URL to the ZenMux endpoint base_url="https://zenmux.ai/api/v1", # 3. Replace with the API Key from your ZenMux user console api_key="", ) # Now you can use the 'client' object to make API calls... # Example: # response = client.chat.completions.create( # model="openai/gpt-5-nano", # messages=[{"role": "user", "content": "Hello!"}], # response_format={"type": "json_object"} # ) # print(response.choices[0].message.content) ``` ### Response N/A (Client Initialization) #### Response Example N/A ``` -------------------------------- ### Send POST Request to ZenMux AI API (Python) Source: https://docs.zenmux.ai/guide/quickstart This Python snippet demonstrates how to send a POST request to the ZenMux AI API to get chat completions. It uses the httpx library for making HTTP requests. The code includes setting up headers and payload, sending the request, checking for success, and printing the JSON response. Ensure the httpx library is installed (`pip install httpx`). ```python import httpx headers = { "Authorization": "Bearer ", "Content-Type": "application/json" } payload = { "model": "openai/gpt-5", "messages": [ { "role": "user", "content": "What is the meaning of life?" } ] } response = httpx.post( "https://zenmux.ai/api/v1/chat/completions", headers=headers, json=payload, timeout=httpx.Timeout(60.0) ) response.raise_for_status() print(response.json()) ``` -------------------------------- ### Tool Calling Flow Example (Python) Source: https://docs.zenmux.ai/guide/advanced/tool-calls Demonstrates a complete tool calling flow using the get_horoscope tool to fetch a daily horoscope for a zodiac sign. This involves defining tools, making an initial request, receiving a tool call, executing the tool, and then sending the tool output back to the model for a final response. ```APIDOC ## Tool Calling Flow Example (Python) ### Description This example illustrates how to use the Tool Calling API with Python to get a daily horoscope. It covers defining a tool, making an initial API call, processing the model's tool call, executing the tool, and then obtaining a final response from the model. ### Method POST ### Endpoint `/v1/chat/completions` (Assumed endpoint for chat completions) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **model** (string) - Required - The model to use for the completion. - **messages** (array) - Required - A list of message objects representing the conversation history. - **role** (string) - Required - The role of the message author ('user', 'assistant', or 'system'). - **content** (string) - Required - The content of the message. - **tools** (array) - Optional - A list of tool definitions that the model may call. - **type** (string) - Required - The type of the tool, e.g., 'function'. - **function** (object) - Required - The function definition. - **name** (string) - Required - The name of the function to call. - **description** (string) - Optional - A description of what the function does, used by the model to determine when to call it. - **parameters** (object) - Optional - The parameters the function expects. - **type** (string) - Required - The type of the parameter object, usually 'object'. - **properties** (object) - Required - A map of parameter names to their properties. - **param_name** (object) - Required - Properties of a specific parameter. - **type** (string) - Required - The data type of the parameter (e.g., 'string', 'integer', 'boolean'). - **description** (string) - Optional - A description of the parameter. - **required** (array) - Optional - A list of parameter names that are required. - **tool_choice** (string or object) - Optional - Controls how the model responds to tools. Can be 'none', 'auto', or a specific tool object. ### Request Example ```python from openai import OpenAI import json client = OpenAI( base_url="https://zenmux.ai/api/v1", api_key="", ) tools = [ { "type": "function", "function": { "name": "get_horoscope", "description": "Get today\'s horoscope for a zodiac sign.", "parameters": { "type": "object", "properties": { "sign": { "type": "string", "description": "Zodiac sign name, e.g., Taurus or Aquarius", } }, "required": ["sign"], }, }, }, ] input_list = [ {"role": "user", "content": "What\'s my horoscope? I\'m an Aquarius."} ] # This is the first call to the model, it might return a tool call response = client.chat.completions.create( model="model-name", # Replace with your model name messages=input_list, tools=tools, tool_choice="auto", ) response_message = response.choices[0].message # Check if the model wants to call a tool if response_message.tool_calls: # This is where you would execute your tool code # For example, call the get_horoscope function with the arguments provided by the model tool_call_id = response_message.tool_calls[0].id function_name = response_message.tool_calls[0].function.name function_args = json.loads(response_message.tool_calls[0].function.arguments) # Simulate tool execution if function_name == "get_horoscope": horoscope_text = f"Your Aquarius horoscope today is..." tool_output = horoscope_text else: tool_output = "Error: Unknown function called." # Append the assistant's tool call and the tool output to the messages input_list.append(response_message) input_list.append({ "role": "tool", "content": tool_output, "tool_call_id": tool_call_id, }) # Make a second call to the model with the tool output second_response = client.chat.completions.create( model="model-name", # Replace with your model name messages=input_list, ) final_response = second_response.choices[0].message.content print(final_response) else: # If the model did not call a tool, just print its direct response print(response_message.content) ``` ### Response #### Success Response (200) - **id** (string) - Unique identifier for the completion. - **object** (string) - Type of the object, e.g., 'chat.completion'. - **created** (integer) - Unix timestamp of when the completion was created. - **model** (string) - The model used for the completion. - **choices** (array) - A list of completion choices. - **index** (integer) - Index of the choice. - **message** (object) - The message content. - **role** (string) - Role of the message author ('assistant'). - **content** (string) - The text content of the assistant's response. May be null if tool calls are present. - **tool_calls** (array) - Optional. If the model decides to call a tool, this array contains the tool call(s). - **id** (string) - Unique identifier for the tool call. - **type** (string) - Type of the tool call, e.g., 'function'. - **function** (object) - Details of the function call. - **name** (string) - The name of the function to call. - **arguments** (string) - JSON string representing the arguments for the function call. - **finish_reason** (string) - The reason the model stopped generating tokens (e.g., 'stop', 'length', 'tool_calls'). - **usage** (object) - Usage statistics for the completion. - **prompt_tokens** (integer) - Number of tokens in the prompt. - **completion_tokens** (integer) - Number of tokens in the completion. - **total_tokens** (integer) - Total tokens used. #### Response Example (First call - tool call) ```json { "id": "chatcmpl-xxxxxxxxxxxxxxxxx", "object": "chat.completion", "created": 1677652288, "model": "model-name", "choices": [ { "index": 0, "message": { "role": "assistant", "content": null, "tool_calls": [ { "id": "call_xxxxxxxxxxxxxxxxx", "type": "function", "function": { "name": "get_horoscope", "arguments": "{\"sign\": \"Aquarius\"}" } } ] }, "finish_reason": "tool_calls" } ], "usage": { "prompt_tokens": 50, "completion_tokens": 25, "total_tokens": 75 } } ``` #### Response Example (Second call - final answer) ```json { "id": "chatcmpl-yyyyyyyyyyyyyyy", "object": "chat.completion", "created": 1677652289, "model": "model-name", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Your Aquarius horoscope today is..." }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 100, "completion_tokens": 30, "total_tokens": 130 } } ``` ``` -------------------------------- ### Make Chat Completion Request with OpenAI SDK (Python) Source: https://docs.zenmux.ai/guide/quickstart This Python snippet demonstrates how to use the OpenAI SDK to make a chat completion request to the ZenMux API. It requires initializing the client with the ZenMux base URL and API key, then specifying the model and messages for the request. Dependencies include the 'openai' library. ```python from openai import OpenAI # 1. Initialize the OpenAI client client = OpenAI( # 2. Point the base URL to the ZenMux endpoint base_url="https://zenmux.ai/api/v1", # 3. Replace with the API key from your ZenMux console api_key="", ) # 4. Make the request completion = client.chat.completions.create( # 5. Specify the model you want to use in the format "provider/model-name" model="openai/gpt-5", messages=[ { "role": "user", "content": "What is the meaning of life?" } ] ) print(completion.choices[0].message.content) ``` -------------------------------- ### Install Claude Code CLI Source: https://docs.zenmux.ai/best-practices/claude-code Installs the Claude Code CLI globally using either pnpm or npm package managers. Ensure you have Node.js and npm/pnpm installed. ```bash # Install with pnpm (recommended) pnpm install -g @anthropic-ai/claude-code # Or install with npm npm install -g @anthropic-ai/claude-code ``` -------------------------------- ### Make Chat Completion Request with OpenAI SDK (TypeScript) Source: https://docs.zenmux.ai/guide/quickstart This TypeScript snippet shows how to use the OpenAI SDK for making chat completion requests to the ZenMux API. It involves initializing the client with the ZenMux base URL and API key, followed by specifying the model and messages. The 'openai' package is a required dependency. ```typescript import OpenAI from "openai"; // 1. Initialize the OpenAI client const openai = new OpenAI({ // 2. Point the base URL to the ZenMux endpoint baseURL: "https://zenmux.ai/api/v1", // 3. Replace with the API key from your ZenMux console apiKey: "", }); async function main() { // 4. Make the request const completion = await openai.chat.completions.create({ // 5. Specify the model you want to use in the format "provider/model-name" model: "openai/gpt-5", messages: [ { role: "user", content: "What is the meaning of life?", }, ], }); console.log(completion.choices[0].message); } main(); ``` -------------------------------- ### Python Image Generation Source: https://docs.zenmux.ai/guide/advanced/image-generation Example of how to generate an image using the ZenMux Python SDK with Vertex AI. ```APIDOC ## POST /api/vertex-ai/generateContent ### Description Generates images from text prompts using supported Banana models via the Vertex AI protocol. ### Method POST ### Endpoint https://zenmux.ai/api/vertex-ai ### Parameters #### Query Parameters - **api_version** (string) - Required - 'v1' #### Request Body - **model** (string) - Required - The name of the image generation model (e.g., "google/gemini-3-pro-image-preview"). - **contents** (array) - Required - A list of prompts for image generation. - **config** (object) - Required - Configuration for content generation. - **response_modalities** (array) - Required - Must include `["TEXT", "IMAGE"]` for image generation. ### Request Example ```python from google import genai from google.genai import types client = genai.Client( api_key="$ZENMUX_API_KEY", # Replace with your API key vertexai=True, http_options=types.HttpOptions( api_version='v1', base_url='https://zenmux.ai/api/vertex-ai' ), ) prompt = "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme" response = client.models.generate_content( model="google/gemini-3-pro-image-preview", contents=[prompt], config=types.GenerateContentConfig( response_modalities=["TEXT", "IMAGE"] ) ) for part in response.parts: if part.text is not None: print(part.text) elif part.inline_data is not None: image = part.as_image() image.save("generated_image.png") print("Image saved as generated_image.png") ``` ### Response #### Success Response (200) - **parts** (array) - Contains text and/or image data. - **text** (string) - Textual part of the response. - **inline_data** (object) - Image data. #### Response Example ```json { "parts": [ { "text": "Here is the image you requested." }, { "inline_data": { "mime_type": "image/png", "data": "base64_encoded_image_data" } } ] } ``` ``` -------------------------------- ### Handling Tool Calls Source: https://docs.zenmux.ai/guide/advanced/tool-calls Understand how to execute tool calls returned by the model and submit their results. ```APIDOC ## Handling Tool Calls When the model invokes your tools, you are responsible for executing them and returning the results. Since a tool call can contain multiple function calls, it's best practice to anticipate and handle them. ### Tool Call Structure The response's `tool_calls` array contains function calls, each identified by `type: "function"`. Each call object includes: - **id** (string): A unique identifier for the tool call, used when submitting results. - **type** (string): The type of tool, typically `function`. - **function** (object): Contains function-specific details: - **name** (string): The name of the function to be called. - **arguments** (string): A JSON-encoded string representing the arguments for the function. ### Example Response with Multiple Tool Calls ```json [ { "id": "fc_12345xyz", "type": "function", "function": { "name": "get_weather", "arguments": "{\"location\":\"Paris, France\"}" } }, { "id": "fc_67890abc", "type": "function", "function": { "name": "get_weather", "arguments": "{\"location\":\"Bogotá, Colombia\"}" } }, { "id": "fc_99999def", "type": "function", "function": { "name": "send_email", "arguments": "{\"to\":\"bob@email.com\",\"body\":\"Hi bob\"}" } } ] ``` ### Executing Tool Calls and Attaching Results **Python Example:** ```python import json input_list = [] # Assume this list is part of the conversation history for choice in response.choices: for tool_call in choice.message.tool_calls or []: if tool_call.type != "function": continue name = tool_call.function.name args = json.loads(tool_call.function.arguments) # Assume call_function is defined elsewhere to execute the actual function result = call_function(name, args) input_list.append({ "role": "tool", "name": name, "tool_call_id": tool_call.id, "content": str(result) }) def call_function(name, args): if name == "get_weather": # Placeholder for actual get_weather function call return f"Weather for {args.get('location')}" if name == "send_email": # Placeholder for actual send_email function call return "email sent successfully" ``` **TypeScript Example:** ```typescript // Assume 'input' is an array to which tool results will be added for (const choice of response.choices) { for (const toolCall of choice.tool_calls) { if (toolCall.type !== "function") { continue; } const name = toolCall.function.name; const args = JSON.parse(toolCall.function.arguments); // Assume callFunction is defined elsewhere to execute the actual function const result = await callFunction(name, args); input.push({ role: "tool", name: name, tool_call_id: toolCall.id, content: result.toString() }); } } const callFunction = async (name: string, args: unknown): Promise => { if (name === "get_weather") { // Placeholder for actual getWeather function call return `Weather for ${args.location}`; } if (name === "send_email") { // Placeholder for actual sendEmail function call return "email sent successfully"; } return "Unknown function"; }; ``` ### Formatting Results Results returned from executed tools must be strings. The content of this string can be any format (JSON, plain text, error codes) that the model can interpret. For tools without a return value, such as `send_email`, return a string indicating success or failure (e.g., `"success"`). ``` -------------------------------- ### TypeScript Image Generation Source: https://docs.zenmux.ai/guide/advanced/image-generation Example of how to generate an image using the ZenMux TypeScript SDK with Vertex AI. ```APIDOC ## POST /api/vertex-ai/generateContent ### Description Generates images from text prompts using supported Banana models via the Vertex AI protocol. ### Method POST ### Endpoint https://zenmux.ai/api/vertex-ai ### Parameters #### Query Parameters - **api_version** (string) - Required - 'v1' #### Request Body - **model** (string) - Required - The name of the image generation model (e.g., "google/gemini-3-pro-image-preview"). - **contents** (string or array) - Required - Prompts for image generation. - **config** (object) - Required - Configuration for content generation. - **responseModalities** (array) - Required - Must include `["TEXT", "IMAGE"]` for image generation. ### Request Example ```typescript const genai = require("@google/genai"); const client = new genai.GoogleGenAI({ apiKey: "$ZENMUX_API_KEY", // Replace with your API key vertexai: true, httpOptions: { baseUrl: "https://zenmux.ai/api/vertex-ai", apiVersion: "v1" } }); const response = await client.models.generateContent({ model: "google/gemini-3-pro-image-preview", contents: "Generate an image of the Eiffel tower with fireworks in the background", config: { responseModalities: ["TEXT", "IMAGE"], } }); console.log(response); ``` ### Response #### Success Response (200) - **candidates** (array) - Contains response candidates. - **content** (object) - **parts** (array) - Contains text and/or image data. - **text** (string) - Textual part of the response. - **inlineData** (object) - Image data. - **mimeType** (string) - The MIME type of the image (e.g., "image/png"). - **data** (string) - Base64 encoded image data. #### Response Example ```json { "candidates": [ { "content": { "parts": [ { "text": "Here is the image you requested." }, { "inlineData": { "mimeType": "image/png", "data": "base64_encoded_image_data" } } ] } } ] } ``` ``` -------------------------------- ### Chat Completions API Source: https://docs.zenmux.ai/guide/quickstart This endpoint allows you to send a POST request to get chat completions from the ZENMUX AI model. It supports various programming languages for integration. ```APIDOC ## POST /api/v1/chat/completions ### Description This endpoint allows you to send a POST request to get chat completions from the ZENMUX AI model. It supports various programming languages for integration. ### Method POST ### Endpoint https://zenmux.ai/api/v1/chat/completions ### Parameters #### Headers - **Authorization** (string) - Required - Bearer token for authentication (e.g., Bearer ) - **Content-Type** (string) - Required - Must be application/json #### Request Body - **model** (string) - Required - The model to use for completions (e.g., "openai/gpt-5") - **messages** (array) - Required - An array of message objects, where each object has a 'role' (user or assistant) and 'content' (the message text). - **role** (string) - Required - The role of the message sender ('user' or 'assistant') - **content** (string) - Required - The content of the message ### Request Example ```json { "model": "openai/gpt-5", "messages": [ { "role": "user", "content": "What is the meaning of life?" } ] } ``` ### Response #### Success Response (200) - **choices** (array) - An array of completion choices. - **message** (object) - The message object containing the response. - **role** (string) - The role of the sender (assistant). - **content** (string) - The generated content from the model. #### Response Example ```json { "choices": [ { "message": { "role": "assistant", "content": "The meaning of life is a profound philosophical question that has been debated for centuries..." } } ] } ``` ``` -------------------------------- ### API Call Example in Python Source: https://docs.zenmux.ai/guide/advanced/structured-output This Python code demonstrates how to initialize the OpenAI client using the ZenMux endpoint and API key for making API calls. ```python from openai import OpenAI # 1. Initialize the OpenAI client client = OpenAI( # 2. Point the base URL to the ZenMux endpoint base_url="https://zenmux.ai/api/v1", # 3. Replace with the API Key from your ZenMux user console api_key="", ) ``` -------------------------------- ### Install Codex CLI with pnpm or npm Source: https://docs.zenmux.ai/best-practices/codex Installs the Codex CLI tool globally using either pnpm or npm package managers. Ensure you have Node.js and a package manager installed. ```bash # Install with pnpm (recommended) pnpm install -g @openai/codex # Or install with npm npm install -g @openai/codex ``` -------------------------------- ### Define Tools and Initial Prompt (Python) Source: https://docs.zenmux.ai/guide/advanced/tool-calls This Python snippet demonstrates how to define a list of callable tools for the model, including their names, descriptions, and parameters. It also initializes the message list for the conversation with the user's prompt. ```Python from openai import OpenAI import json client = OpenAI( base_url="https://zenmux.ai/api/v1", api_key="", ) # 1. Define the list of callable tools for the model tools = [ { "type": "function", "function": { "name": "get_horoscope", "description": "Get today's horoscope for a zodiac sign.", "parameters": { "type": "object", "properties": { "sign": { "type": "string", "description": "Zodiac sign name, e.g., Taurus or Aquarius", }, }, "required": ["sign"], }, }, }, ] # Create a message list that we'll append to over time input_list = [ {"role": "user", "content": "What's my horoscope? I'm an Aquarius."} ] ``` -------------------------------- ### Prompt Model with Tools (Python) Source: https://docs.zenmux.ai/guide/advanced/tool-calls This Python snippet demonstrates how to prompt a model using defined tools. It shows the process of creating a completion request, handling tool calls, executing a Python function based on tool arguments, and sending the result back to the model. The code uses the 'moonshotai/kimi-k2' model and assumes a client object is already configured. ```python import json # Assuming 'client' is an initialized ZenMux AI client # and 'tools' and 'input_list' are pre-defined. # 2. Prompt the model with the defined tools response = client.chat.completions.create( model="moonshotai/kimi-k2", tools=tools, messages=input_list, ) # Save the function call outputs for a subsequent request function_call = None function_call_arguments = None input_list.append({ "role": "assistant", "content": response.choices[0].message.content, "tool_calls": [tool_call.model_dump() for tool_call in response.choices[0].message.tool_calls] if response.choices[0].message.tool_calls else None, }) for item in response.choices[0].message.tool_calls: if item.type == "function": function_call = item function_call_arguments = json.loads(item.function.arguments) def get_horoscope(sign): return f"{sign}: You will meet a baby otter next Tuesday." # 3. Execute the function logic for get_horoscope result = {"horoscope": get_horoscope(function_call_arguments["sign"])} # 4. Provide the function call result back to the model input_list.append({ "role": "tool", "tool_call_id": function_call.id, "name": function_call.function.name, "content": json.dumps(result), }) print("Final input:") print(json.dumps(input_list, indent=2, ensure_ascii=False)) response = client.chat.completions.create( model="moonshotai/kimi-k2", tools=tools, messages=input_list, ) # 5. The model should now be able to respond! print("Final output:") print(response.model_dump_json(indent=2)) print("\n" + response.choices[0].message.content) ``` -------------------------------- ### Start Codex CLI after Configuration Source: https://docs.zenmux.ai/best-practices/codex Reloads your shell configuration to apply environment variable changes and then launches the Codex CLI. Navigate to your project directory before starting Codex to enable it to read and modify your code. ```bash # Reload the configuration file source ~/.zshrc # or source ~/.bashrc # Go to your project directory cd my-project # Start Codex CLI codex ``` -------------------------------- ### OpenAI Basic Implicit Caching Example (Python) Source: https://docs.zenmux.ai/guide/advanced/prompt-cache Demonstrates basic usage of the OpenAI Python SDK with ZenMux AI for implicit prompt caching. This code initializes the client with the ZenMux API base URL and your API key. Implicit caching requires no special parameters, as the model automatically handles caching for supported providers. ```python from openai import OpenAI client = OpenAI( base_url="https://zenmux.ai/api/v1", api_key="", ) ``` -------------------------------- ### Python: Basic Reasoning Control with OpenAI SDK Source: https://docs.zenmux.ai/guide/advanced/reasoning Demonstrates basic reasoning control using the OpenAI Python SDK by passing the `reasoning_effort` parameter directly. This method offers intensity level control but lacks precise `max_tokens` settings. ```python from openai import OpenAI import os client = OpenAI( base_url="https://zenmux.ai/api/v1", api_key=os.getenv("ZENMUX_API_KEY"), ) completion = client.chat.completions.create( model="qwen/qwen3-max-preview", reasoning_effort="high", messages=[ { "role": "user", "content": "What is the meaning of life?" } ] ) print(completion.choices[0]) ``` -------------------------------- ### Merging Results and Final Response Source: https://docs.zenmux.ai/guide/advanced/tool-calls After processing tool results, you can send them back to the model to generate a final, synthesized response. Examples are provided for Python and TypeScript. ```APIDOC ## POST /chat/completions (Conceptual) ### Description This endpoint is used to send messages and tools to the model to receive a completion. After appending results from tool calls to your input messages, you can send them back to the model to generate a final response. ### Method POST ### Endpoint /chat/completions ### Parameters #### Request Body - **model** (string) - Required - The model to use for completion (e.g., "moonshotai/kimi-k2"). - **messages** (array) - Required - A list of message objects representing the conversation history and tool results. - **tools** (array) - Optional - A list of tool definitions the model can use. ### Request Example (Python) ```python response = client.chat.completions.create( model="moonshotai/kimi-k2", messages=input_messages, tools=tools, ) ``` ### Request Example (TypeScript) ```typescript const response = await openai.chat.completions.create({ model: "moonshotai/kimi-k2", messages: input, tools, }); ``` ### Response #### Success Response (200) - **content** (string) - The final synthesized response from the model. #### Response Example ```json { "content": "It's about 15°C in Paris and about 18°C in Bogotá. I’ve sent that email to Bob." } ``` ``` -------------------------------- ### Example JSON Output Events for Streaming Source: https://docs.zenmux.ai/guide/advanced/tool-calls Illustrates the structure of JSON event objects received when streaming tool calls. These events contain incremental updates from the model, including content segments and tool call information, allowing for real-time processing. ```json {"content":"I need","role":"assistant"} {"content":"the coordinates of Paris","role":"assistant"} {"content":" to","role":"assistant"} {"content":" fetch","role":"assistant"} {"content":" the","role":"assistant"} {"content":" weather","role":"assistant"} {"content":" information","role":"assistant"} {"content":".","role":"assistant"} {"content":"Paris's","role":"assistant"} {"content":" latitude","role":"assistant"} {"content":" is about","role":"assistant"} {"content":" 48","role":"assistant"} {"content":".","role":"assistant"} {"content":"856","role":"assistant"} {"content":"6","role":"assistant"} {"content":",","role":"assistant"} {"content":" and","role":"assistant"} {"content":" the","role":"assistant"} {"content":" longitude","role":"assistant"} {"content":" is","role":"assistant"} {"content":" 2","role":"assistant"} {"content":".","role":"assistant"} {"content":"352","role":"assistant"} {"content":"2","role":"assistant"} {"content":".","role":"assistant"} {"content":"Let me","role":"assistant"} {"content":" check","role":"assistant"} {"content":" today's","role":"assistant"} {"content":" weather","role":"assistant"} {"content":" in Paris","role":"assistant"} {"content":".","role":"assistant"} {"content":"","role":"assistant","tool_calls":[{"index":0,"id":"get_weather:0","function":{"arguments":"","name":"get_weather"},"type":"function"}]} {"content":"","role":"assistant","tool_calls":[{"index":0,"function":{"arguments":"{\""}}]} {"content":"","role":"assistant","tool_calls":[{"index":0,"function":{"arguments":"latitude"}}]} {"content":"","role":"assistant","tool_calls":[{"index":0,"function":{"arguments":"\":"}}]} {"content":"","role":"assistant","tool_calls":[{"index":0,"function":{"arguments":" "}}]} {"content":"","role":"assistant","tool_calls":[{"index":0,"function":{"arguments":"48"}}]} {"content":"","role":"assistant","tool_calls":[{"index":0,"function":{"arguments":"."}}]} {"content":"","role":"assistant","tool_calls":[{"index":0,"function":{"arguments":"856"}}]} {"content":"","role":"assistant","tool_calls":[{"index":0,"function":{"arguments":"6"}}]} {"content":"","role":"assistant","tool_calls":[{"index":0,"function":{"arguments":","}}]} {"content":"","role":"assistant","tool_calls":[{"index":0,"function":{"arguments":" \""}}]} {"content":"","role":"assistant","tool_calls":[{"index":0,"function":{"arguments":"longitude"}}]} {"content":"","role":"assistant","tool_calls":[{"index":0,"function":{"arguments":"\":"}}]} {"content":"","role":"assistant","tool_calls":[{"index":0,"function":{"arguments":" "}}]} {"content":"","role":"assistant","tool_calls":[{"index":0,"function":{"arguments":"2"}}]} {"content":"","role":"assistant","tool_calls":[{"index":0,"function":{"arguments":"."}}] ``` -------------------------------- ### Implement Function Call Routing Source: https://docs.zenmux.ai/guide/advanced/tool-calls Provides example implementations for routing function calls based on their names. These functions act as dispatchers, calling the appropriate specific function (e.g., get_weather, send_email) with the provided arguments. Supports asynchronous operations in TypeScript. ```python def call_function(name, args): if name == "get_weather": return get_weather(**args) if name == "send_email": return send_email(**args) ``` ```typescript const callFunction = async (name: string, args: unknown) => { if (name === "get_weather") { return getWeather(args.latitude, args.longitude); } if (name === "send_email") { return sendEmail(args.to, args.body); } }; ``` -------------------------------- ### Defining Function Tools Source: https://docs.zenmux.ai/guide/advanced/tool-calls Learn how to define function tools using the 'tools' parameter, specifying their schema, name, description, and parameters. ```APIDOC ## Defining Function Tools Function tools are defined via the `tools` parameter. Each tool requires a schema that details its functionality and expected input parameters. ### Tool Definition Properties - **type** (string) - Must be `function`. - **function** (object) - Contains the function's details: - **name** (string) - The name of the function (e.g., `get_weather`). - **description** (string) - Explains when and how to use the function. - **parameters** (object) - A JSON Schema defining the function's input parameters. This schema should include `type`, `properties`, `required` fields, and optionally `additionalProperties`. - **strict** (boolean) - Optional. Determines if strict schema adherence is enforced during function call generation. ### Example `get_weather` Function Tool Definition ```json { "type": "function", "function": { "name": "get_weather", "description": "Retrieve the current weather for a given location.", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "City and country, e.g., Bogotá, Colombia" }, "units": { "type": "string", "enum": ["celsius", "fahrenheit"], "description": "Unit for the returned temperature." } }, "required": ["location", "units"], "additionalProperties": false }, "strict": true } } ``` ### Token Usage Tools consume tokens from the model's context window and are billed as prompt tokens. To manage token limits, consider minimizing the size and number of tools used. ``` -------------------------------- ### Make Message Request with Anthropic SDK (Python) Source: https://docs.zenmux.ai/guide/quickstart This Python code utilizes the Anthropic SDK to send messages to the ZenMux API, compatible with the Anthropic protocol. It requires setting the `base_url` to the ZenMux Anthropic endpoint and providing your API key. The `anthropic` library is needed for this implementation. ```python from anthropic import Anthropic # 1. Initialize the Anthropic client client = Anthropic( # 2. Point the base URL to the ZenMux endpoint base_url="https://zenmux.ai/api/anthropic", # 3. Replace with the API key from your ZenMux console api_key="", ) # 4. Make the request message = client.messages.create( # 5. Specify the model you want to use in the format "provider/model-name" model="anthropic/claude-sonnet-4.5", max_tokens=1024, messages=[ { "role": "user", "content": "What is the meaning of life?" } ] ) print(message.content[0].text) ``` -------------------------------- ### Define Get Weather Function Tool Schema Source: https://docs.zenmux.ai/guide/advanced/tool-calls Defines the schema for a 'get_weather' function tool. This schema specifies the tool's type, name, description, and expected input parameters (location and units) using JSON Schema. It also enforces strict schema adherence. ```json { "type": "function", "function": { "name": "get_weather", "description": "Retrieve the current weather for a given location.", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "City and country, e.g., Bogotá, Colombia" }, "units": { "type": "string", "enum": ["celsius", "fahrenheit"], "description": "Unit for the returned temperature." } }, "required": ["location", "units"], "additionalProperties": false }, "strict": true } } ``` -------------------------------- ### Configure ZenMux using Configuration File (JSON) Source: https://docs.zenmux.ai/best-practices/neovate-code Defines ZenMux configuration using a JSON file, including the API key and endpoint. This method is suitable for more complex configurations or legacy systems. The 'apiKey' and 'api' fields should be populated with your specific details. ```json { "zenmux": { "apiKey": "your_zenmux_api_key_here", "api": "https://zenmux.ai/api/v1" } } ``` -------------------------------- ### Stream Tool Calls with TypeScript Source: https://docs.zenmux.ai/guide/advanced/tool-calls Shows how to stream tool calls using the OpenAI TypeScript library with ZenMux AI. This method also requires setting `stream: true` and using an async iterator to process events. Ensure you have the `openai` package installed and your API key configured. ```typescript import { OpenAI } from "openai"; const openai = new OpenAI({ baseURL: 'https://zenmux.ai/api/v1', apiKey: '', }); const tools: OpenAI.Chat.Completions.ChatCompletionTool[] = [{ type: "function", function: { name: "get_weather", description: "Get the current temperature (Celsius) for the provided coordinates.", parameters: { type: "object", properties: { latitude: { type: "number" }, longitude: { type: "number" } }, required: ["latitude", "longitude"], additionalProperties: false }, strict: true, }, }]; async function main() { const stream = await openai.chat.completions.create({ model: "moonshotai/kimi-k2", messages: [{ role: "user", content: "How's the weather in Paris today?" }], tools, stream: true, }); for await (const event of stream) { console.log(JSON.stringify(event.choices[0].delta)); } } main() ```