### .NET SDK Setup Source: https://docs.apiyi.com/en/api-capabilities/openai/compatible Install the OpenAI .NET package and configure the client with your API key and the compatible API base URL. This example demonstrates getting a chat client and completing a chat. ```bash dotnet add package OpenAI ``` ```csharp using OpenAI; using OpenAI.Chat; var client = new OpenAIClient( new System.ClientModel.ApiKeyCredential("YOUR_API_KEY"), new OpenAIClientOptions { Endpoint = new Uri("https://api.apiyi.com/v1") } ); var chatClient = client.GetChatClient("gpt-5.4"); var response = await chatClient.CompleteChatAsync("Hello!"); Console.WriteLine(response.Value.Content[0].Text); ``` -------------------------------- ### Go SDK Setup Source: https://docs.apiyi.com/en/api-capabilities/openai/compatible Install the official OpenAI Go SDK and configure the client with your API key and the compatible API base URL. This example shows how to create a new chat completion. ```bash go get github.com/openai/openai-go ``` ```go package main import ( "context" "fmt" "github.com/openai/openai-go" "github.com/openai/openai-go/option" ) func main() { client := openai.NewClient( option.WithAPIKey("YOUR_API_KEY"), option.WithBaseURL("https://api.apiyi.com/v1"), ) completion, err := client.Chat.Completions.New(context.TODO(), openai.ChatCompletionNewParams{ Model: "gpt-5.4", Messages: []openai.ChatCompletionMessageParamUnion{ openai.UserMessage("Hello!"), }, }) if err != nil { panic(err) } fmt.Println(completion.Choices[0].Message.Content) } ``` -------------------------------- ### Python OpenAI SDK Examples for Qwen3.6 Source: https://docs.apiyi.com/en/api-capabilities/qwen-3-6/overview Use these examples to interact with Qwen3.6 models via the OpenAI SDK. Ensure you have the SDK installed and replace 'sk-your-api-key' with your actual API key. The `base_url` should be set to 'https://api.apiyi.com/v1'. ```python from openai import OpenAI client = OpenAI( api_key="sk-your-api-key", base_url="https://api.apiyi.com/v1" ) # Max-Preview: coding Agent driver resp = client.chat.completions.create( model="qwen3.6-max-preview", messages=[ {"role": "system", "content": "You are a senior Python engineer. Return changes as a unified diff."}, {"role": "user", "content": "Add type hints and fix any latent bugs in this snippet ..."} ] ) print(resp.choices[0].message.content) ``` ```python # Flash: image + text multimodal input resp = client.chat.completions.create( model="qwen3.6-flash", messages=[ {"role": "user", "content": [ {"type": "text", "text": "Describe the key information in this image."}, {"type": "image_url", "image_url": {"url": "https://your-image-url.png"}} ]} ] ) print(resp.choices[0].message.content) ``` ```python # Plus: daily dialog and mid-complexity reasoning resp = client.chat.completions.create( model="qwen3.6-plus", messages=[{"role": "user", "content": "Introduce yourself in one sentence."}] ) print(resp.choices[0].message.content) ``` -------------------------------- ### Quickstart: OpenAI-Compatible API Source: https://docs.apiyi.com/en/news/kimi-k2-6-launch Initialize the OpenAI client with your API key and base URL to interact with the Kimi K2.6 model. This example demonstrates a typical use case for agentic coding and tool calls. ```python from openai import OpenAI client = OpenAI( api_key="sk-your-apiyi-key", base_url="https://api.apiyi.com/v1" ) # Typical use: agentic coding + tool calls resp = client.chat.completions.create( model="kimi-k2.6", messages=[ {"role": "system", "content": "You are a senior full-stack engineer who ships real PR-scale work in production repos."}, {"role": "user", "content": "Migrate this repo's logging layer to structlog and produce the minimal-diff PR."} ], temperature=0.3, ) print(resp.choices[0].message.content) ``` -------------------------------- ### Node.js OpenAI SDK Example for Qwen3.6 Source: https://docs.apiyi.com/en/api-capabilities/qwen-3-6/overview This Node.js example demonstrates how to use the OpenAI SDK to interact with Qwen3.6 models. Ensure you have the SDK installed and replace 'sk-your-api-key' with your actual API key. Set `baseURL` to 'https://api.apiyi.com/v1'. ```javascript import OpenAI from 'openai'; const client = new OpenAI({ apiKey: 'sk-your-api-key', baseURL: 'https://api.apiyi.com/v1', }); const resp = await client.chat.completions.create({ model: 'qwen3.6-plus', messages: [{ role: 'user', content: 'Introduce yourself in one sentence.' }], }); console.log(resp.choices[0].message.content); ``` -------------------------------- ### Python SDK Setup Source: https://docs.apiyi.com/en/api-capabilities/openai/compatible Install the OpenAI Python SDK and configure the client with your API key and the compatible API base URL. Alternatively, use environment variables for configuration. ```bash pip install openai ``` ```python from openai import OpenAI, AsyncOpenAI # Synchronous client client = OpenAI( api_key="YOUR_API_KEY", base_url="https://api.apiyi.com/v1" ) # Async client async_client = AsyncOpenAI( api_key="YOUR_API_KEY", base_url="https://api.apiyi.com/v1" ) ``` ```bash export OPENAI_API_KEY="YOUR_API_KEY" export OPENAI_BASE_URL="https://api.apiyi.com/v1" ``` ```python from openai import OpenAI client = OpenAI() # reads the environment automatically ``` -------------------------------- ### Java SDK Setup Source: https://docs.apiyi.com/en/api-capabilities/openai/compatible Add the official OpenAI Java SDK to your project and configure the client with your API key and the compatible API base URL. This example demonstrates creating a chat completion. ```xml com.openai openai-java LATEST ``` ```java import com.openai.client.OpenAIClient; import com.openai.client.okhttp.OpenAIOkHttpClient; import com.openai.models.chat.completions.ChatCompletion; import com.openai.models.chat.completions.ChatCompletionCreateParams; OpenAIClient client = OpenAIOkHttpClient.builder() .apiKey("YOUR_API_KEY") .baseUrl("https://api.apiyi.com/v1") .build(); ChatCompletionCreateParams params = ChatCompletionCreateParams.builder() .model("gpt-5.4") .addUserMessage("Hello!") .build(); ChatCompletion completion = client.chat().completions().create(params); System.out.println(completion.choices().get(0).message().content().orElse("")); ``` -------------------------------- ### Quick Start Image Generation (Google Native Format) Source: https://docs.apiyi.com/en/news/nano-banana-2-launch This example demonstrates how to generate an image using the recommended Google Native Format. It requires the 'requests' and 'base64' libraries. The generated image is saved as 'output.png'. ```python import requests import base64 API_KEY = "sk-your-api-key" response = requests.post( "https://api.apiyi.com/v1beta/models/gemini-3.1-flash-image-preview:generateContent", headers={"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"}, json={ "contents": [{"parts": [{"text": "A cute Shiba Inu sitting under cherry blossom trees, watercolor style"}]}], "generationConfig": { "responseModalities": ["IMAGE"], "imageConfig": {"aspectRatio": "16:9", "imageSize": "2K"} } }, timeout=300 ).json() img_data = response["candidates"][0]["content"]["parts"][0]["inlineData"]["data"] with open("output.png", 'wb') as f: f.write(base64.b64decode(img_data)) print("Image saved") ``` -------------------------------- ### Gemini Native Format Quick Start Source: https://docs.apiyi.com/en/api-capabilities/gemini/native Examples demonstrating how to call the Gemini native format using the google-genai SDK in Python, Node.js, and cURL. ```APIDOC ## Gemini Native Format Quick Start Use Google's official unified SDK `google-genai`: ```bash pip install google-genai ``` ### Python Example ```python from google import genai client = genai.Client( api_key="YOUR_API_KEY", # your APIYI key http_options={"base_url": "https://api.apiyi.com"} ) response = client.models.generate_content( model="gemini-3.5-flash", contents="Introduce yourself in one sentence" ) print(response.text) ``` ### Node.js Example ```javascript import { GoogleGenAI } from '@google/genai'; const ai = new GoogleGenAI({ apiKey: 'YOUR_API_KEY', httpOptions: { baseUrl: 'https://api.apiyi.com' } }); const response = await ai.models.generateContent({ model: 'gemini-3.5-flash', contents: 'Introduce yourself in one sentence' }); console.log(response.text); ``` ### cURL Example ```bash curl "https://api.apiyi.com/v1beta/models/gemini-3.5-flash:generateContent" \ -H "Content-Type: application/json" \ -H "x-goog-api-key: YOUR_API_KEY" \ -d '{ "contents": [{"parts": [{"text": "Introduce yourself in one sentence"}]}] }' ``` **Note**: The `base_url` is `https://api.apiyi.com` (without `/v1`). Use your APIYI key, not a Google AI Studio key. ``` -------------------------------- ### Get Text Embedding with OpenAI SDK Source: https://docs.apiyi.com/en/api-capabilities/text-embedding This Python example demonstrates how to get a vector representation of a single text using the OpenAI SDK. Ensure you have the SDK installed and replace YOUR_API_KEY with your actual API key. ```python from openai import OpenAI client = OpenAI( api_key="YOUR_API_KEY", base_url="https://api.apiyi.com/v1" ) def get_embedding(text, model="text-embedding-3-small"): """Get vector representation of text""" response = client.embeddings.create( input=text, model=model ) return response.data[0].embedding # Usage example text = "Artificial intelligence is changing the world" embedding = get_embedding(text) print(f"Vector dimensions: {len(embedding)}") print(f"First 5 values: {embedding[:5]}") ``` -------------------------------- ### Python Integration Example Source: https://docs.apiyi.com/en/scenarios/chat/open-webui Basic Python script setup for integrating with an API. This snippet requires the `requests` library and serves as a starting point for API interactions. ```python import requests ``` -------------------------------- ### Document Q&A System Setup Source: https://docs.apiyi.com/en/scenarios/engineering/langchain Set up a Document Q&A system by loading, splitting, and embedding documents, then creating a RetrievalQA chain. ```python from langchain.document_loaders import TextLoader from langchain.text_splitter import CharacterTextSplitter from langchain.embeddings import OpenAIEmbeddings from langchain.vectorstores import FAISS from langchain.chains import RetrievalQA embeddings = OpenAIEmbeddings( api_key="Your APIYI key", base_url="https://api.apiyi.com/v1" ) loader = TextLoader("document.txt") documents = loader.load() text_splitter = CharacterTextSplitter( chunk_size=1000, chunk_overlap=0 ) texts = text_splitter.split_documents(documents) vectorstore = FAISS.from_documents(texts, embeddings) qa = RetrievalQA.from_chain_type( llm=llm, chain_type="stuff", retriever=vectorstore.as_retriever() ) result = qa.run("What are the key concepts in the document?") ``` -------------------------------- ### Node.js / TypeScript SDK Setup Source: https://docs.apiyi.com/en/api-capabilities/openai/compatible Install the OpenAI Node.js SDK and configure the client with your API key and the compatible API base URL. This example shows how to make a chat completion request. ```bash npm install openai ``` ```typescript import OpenAI from 'openai'; const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY, baseURL: 'https://api.apiyi.com/v1' }); const response = await openai.chat.completions.create({ model: 'gpt-5.4-mini', messages: [{ role: 'user', content: 'Hello!' }], temperature: 0.7 }); ``` -------------------------------- ### Run OpenClaw Setup Wizard Source: https://docs.apiyi.com/en/scenarios/agent/openclaw/config-cli Initiates the interactive setup wizard for new users to configure OpenClaw. Follow the prompts to set up model providers, API keys, and other settings. ```bash openclaw onboard ``` -------------------------------- ### Start FastClaw Service Source: https://docs.apiyi.com/en/scenarios/agent/fastclaw Commands to start FastClaw in the foreground, as a background daemon, or install it as a system service. ```bash fastclaw # Foreground (Ctrl+C to stop) fastclaw daemon start # Background (logs at ~/.fastclaw/daemon.log) fastclaw daemon install # Register as a launchd / systemd service ``` -------------------------------- ### Quickstart with OpenAI-compatible API Source: https://docs.apiyi.com/en/news/deepseek-v4-launch Use this snippet to interact with Deepseek V4 models via an OpenAI-compatible API. Configure your API key and base URL. The `reasoning_effort` parameter can be set to 'max' for complex tasks. ```python from openai import OpenAI client = OpenAI( api_key="sk-your-apiyi-key", base_url="https://api.apiyi.com/v1" ) # Flagship: V4-Pro at max reasoning effort for complex agents resp = client.chat.completions.create( model="deepseek-v4-pro", messages=[ {"role": "system", "content": "You are a senior full-stack engineer."}, {"role": "user", "content": "Implement a circuit-breaker retry strategy for login in the existing repo."} ], extra_body={"reasoning_effort": "max"} ) print(resp.choices[0].message.content) ``` -------------------------------- ### Generate Product Photography with GPT-Image-1.5 Source: https://docs.apiyi.com/en/api-capabilities/gpt-image-1-5 This example demonstrates generating professional product photography. The prompt should detail the product, setting, lighting, and desired angle for optimal results. ```python {/* Product showcase example */} response = client.images.generate( model="gpt-image-1.5", prompt="Professional product photography of modern wireless earbuds case on white marble surface, soft studio lighting, 45-degree angle, clean background", size="1024x1024", quality="high" ) ``` -------------------------------- ### Get Text Embedding with curl Source: https://docs.apiyi.com/en/api-capabilities/text-embedding Use this command-line example to quickly get a text embedding. Replace YOUR_API_KEY with your actual API key. ```bash curl https://api.apiyi.com/v1/embeddings \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ -d '{ "input": "Artificial intelligence is changing the world", "model": "text-embedding-3-small" }' ``` -------------------------------- ### Set Model ID in Setup Source: https://docs.apiyi.com/en/scenarios/agent/openclaw/config-cli Enter the desired model ID for your configuration during the OpenClaw setup. Examples include 'gpt-5.4', 'claude-sonnet-4-6', etc. ```text gpt-5.4 ``` -------------------------------- ### Example of a Good Prompt for HTTP Middleware Source: https://docs.apiyi.com/en/scenarios/programming/opencode Use specific and detailed prompts to guide the AI in generating the desired code. This example shows how to request an HTTP middleware in TypeScript with logging capabilities. ```text ❌ Poor prompt: Help me write code ✅ Good prompt: Write an HTTP middleware in TypeScript that logs requests, including request method, path, response time, and status code, using pino for output ``` -------------------------------- ### Structured Prompt Example Source: https://docs.apiyi.com/en/scenarios/engineering/dify This text example outlines a structured prompt format for Dify applications, including role definition, task description, output format, and constraints. This helps in guiding the model to produce desired outputs. ```text # Structured Prompt ## Role Definition You are a professional [specific role] ## Task Description Please help users with [specific task] ## Output Format Please output in the following format: 1. Overview 2. Detailed Analysis 3. Recommendations ## Constraints - Answers must be accurate - Language should be clear - Keep length within 500 words ``` -------------------------------- ### Install OpenCode via cURL Source: https://docs.apiyi.com/en/scenarios/programming/opencode Use this command for a quick and recommended installation of OpenCode. ```bash curl -fsSL https://opencode.ai/install | bash ``` -------------------------------- ### Start OpenCode in Current Directory Source: https://docs.apiyi.com/en/scenarios/programming/opencode Launches the OpenCode interactive terminal in the current working directory. No additional setup is required. ```bash opencode ``` -------------------------------- ### Install google-genai SDK Source: https://docs.apiyi.com/en/api-capabilities/gemini/native Install the official Google unified SDK for Gemini. Use this SDK for the native Gemini API. ```bash pip install google-genai ``` -------------------------------- ### Start Hermes Agent TUI Source: https://docs.apiyi.com/en/scenarios/agent/hermes-agent After installation, reload your shell and use this command to launch the Hermes Agent's Text-based User Interface (TUI). ```bash source ~/.bashrc # or source ~/.zshrc hermes # Launches the TUI, ready to chat ``` -------------------------------- ### Quick Start: Gemini Native Format in Python Source: https://docs.apiyi.com/en/api-capabilities/gemini/native Initialize the Gemini client with your APIYI key and the APIYI base URL. Then, generate content using the specified model. ```python from google import genai client = genai.Client( api_key="YOUR_API_KEY", # your APIYI key http_options={"base_url": "https://api.apiyi.com"} ) response = client.models.generate_content( model="gemini-3.5-flash", contents="Introduce yourself in one sentence" ) print(response.text) ``` -------------------------------- ### Prompt Optimization Example Source: https://docs.apiyi.com/en/scenarios/chat/chatgpt-next-web Structure your prompts effectively by defining a role, task, and output requirements. This helps in getting more precise and relevant responses from the AI. ```markdown # Role Setting You are an experienced [specific role] # Task Description Please help me [specific task] # Output Requirements - Requirement 1 - Requirement 2 ``` -------------------------------- ### Install OpenClaw using Quick Install Script Source: https://docs.apiyi.com/en/scenarios/agent/openclaw/installation Execute a curl command to download and run the OpenClaw installation script on Linux/macOS. ```bash curl -fsSL https://openclaw.ai/install.sh | bash ``` -------------------------------- ### Prompt Optimization Examples Source: https://docs.apiyi.com/en/api-capabilities/gpt-image-1 Examples demonstrating how to improve image generation results by providing more detailed prompts, specifying artistic styles, and defining composition and perspective. ```python # Basic prompt prompt_basic = "a cat" # Optimized prompt prompt_detailed = "a fluffy white Persian cat sitting on a vintage velvet cushion, soft natural lighting, professional photography, shallow depth of field" ``` ```python styles = [ "in the style of Studio Ghibli anime", "photorealistic, professional photography", "digital art, concept art style", "oil painting, impressionist style", "minimalist, flat design illustration" ] ``` ```python compositions = [ "close-up portrait, centered composition", "wide angle landscape shot, rule of thirds", "aerial view, bird's eye perspective", "low angle shot, dramatic perspective" ] ``` -------------------------------- ### Get Programming Assistance from OpenClaw Source: https://docs.apiyi.com/en/scenarios/agent/openclaw/usage Examples of how to ask OpenClaw for help with programming tasks, including script generation, code debugging, and HTML creation. ```text > Write a Python script to batch rename files > What's wrong with this code: [paste code] > Create a simple HTML page for me ``` -------------------------------- ### Code Generation: Go Concurrent Cache Source: https://docs.apiyi.com/en/scenarios/programming/roo-code Example of Roo Code generating Go code for a concurrent-safe cache with Set, Get, Delete, and expired data clearing functionalities. ```go // Requirement: Implement a concurrent-safe cache // Support Set, Get, Delete, clear expired data // Roo Code generates complete Go code package cache import ( "sync" time ) type Cache struct { // ... complete implementation } ``` -------------------------------- ### OpenCode Command Execution Examples Source: https://docs.apiyi.com/en/scenarios/programming/opencode Examples of how to instruct OpenCode to execute terminal commands and analyze their output. Useful for running tests or managing dependencies. ```text > Run npm test and analyze the failed tests ``` ```text > Execute npm install and check for dependency conflicts ``` -------------------------------- ### Good Prompt Example for High-Res Images Source: https://docs.apiyi.com/en/news/nano-banana-pro-launch This example illustrates a good prompt for generating high-resolution images, focusing on detail and professional quality. Vague prompts should be avoided. ```text ✅ Good Prompt: "A 4K ultra-HD product photo, rich details, professional photography, studio lighting, white background, centered product, soft shadows" ❌ Avoid: "Product photo" # Lacks detail ```