Python, Node.js and cURL examples
Prepare your environment
Section titled “Prepare your environment”Set WUDI_API_KEY and choose a text model available to your key. You can replace the example model with an exact available ID. Generation requests are charged according to actual use.
Python with the OpenAI SDK
Section titled “Python with the OpenAI SDK”python -m pip install openaiimport osfrom openai import OpenAI, APIStatusError
client = OpenAI( api_key=os.environ["WUDI_API_KEY"], base_url="https://wudiapi.com/v1", timeout=120, max_retries=0,)try: result = client.chat.completions.create( model="deepseek-v4.1-flash", messages=[{"role":"user","content":"Explain what an API does."}], ) print(result.choices[0].message.content) print(result.usage)except APIStatusError as error: print("HTTP", error.status_code, error.message)Node.js with the OpenAI SDK
Section titled “Node.js with the OpenAI SDK”npm install openaiSave the following as an .mjs file and run it with Node.js:
import OpenAI from 'openai';
if (!process.env.WUDI_API_KEY) throw new Error('Set WUDI_API_KEY');const client = new OpenAI({ apiKey: process.env.WUDI_API_KEY, baseURL: 'https://wudiapi.com/v1', timeout: 120000, maxRetries: 0,});try { const response = await client.chat.completions.create({ model: 'deepseek-v4.1-flash', messages: [{ role: 'user', content: 'Explain what an API does.' }], }); console.log(response.choices[0]?.message?.content); console.log(response.usage);} catch (error) { console.error('Request failed', error.status, error.message);}Windows PowerShell
Section titled “Windows PowerShell”Native HTTP methods avoid complicated JSON quoting in a shell command:
$env:WUDI_API_KEY = 'YOUR_WUDI_API_KEY'$headers = @{ Authorization = "Bearer $env:WUDI_API_KEY" }$body = @{ model = 'deepseek-v4.1-flash' messages = @(@{ role = 'user'; content = 'Hello. Please answer briefly.' }) stream = $false} | ConvertTo-Json -Depth 10Invoke-RestMethod -Uri 'https://wudiapi.com/v1/chat/completions' ` -Method Post -Headers $headers -ContentType 'application/json; charset=utf-8' ` -Body ([Text.Encoding]::UTF8.GetBytes($body))curl --fail-with-body https://wudiapi.com/v1/chat/completions \ -H "Authorization: Bearer $WUDI_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model":"deepseek-v4.1-flash","messages":[{"role":"user","content":"Hello"}]}'Before deployment
Section titled “Before deployment”Validate user input on your server, limit request size and concurrency, and handle errors by type. Keep the key on the backend and exclude authenticated headers from logs. See streaming for incremental output and Responses for that protocol’s structure and availability requirements.
