Skip to main content
Last updated: 2026-06-23

When To Use This Guide

Crazyrouter supports the official OpenAI SDK for OpenAI-compatible routes. Use it for chat, Responses API, images, audio, embeddings, and model listing. For video, Kling, Luma, Suno, Midjourney, and other async or provider-native routes, use the same API key with fetch against Crazyrouter native paths. Default international API entry:
OpenAI SDK base URL:
Do not set the OpenAI SDK baseURL to https://api.crazyrouter.com, because the SDK expects a /v1 base. Do not set it to a full endpoint such as https://api.crazyrouter.com/v1/chat/completions, because the SDK appends endpoint paths itself.

Install The SDK

Use Node.js 18 or later. Node.js 18+ includes fetch, FormData, and Blob.

Configure Environment Variables

macOS / Linux:
Windows PowerShell:

Create A Client

Chat Completions

Streaming

Model Listing

Embeddings

Responses API

Use the Responses API for GPT models that support /v1/responses.
Do not test Claude models through the Responses API. Use /v1/messages or OpenAI-compatible /v1/chat/completions for Claude.

Images, Audio, And Transcription

OpenAI-compatible image and audio routes use the same SDK client.

Native Async Task Routes

Video, Kling, Luma, Suno, Midjourney, and similar async tasks are usually not OpenAI SDK methods. Call Crazyrouter native HTTP paths with the same API key.
Create a unified video task:
Query the task:

Upload A Local Image

For image-to-video, vision, and image-editing inputs, upload local reference images first.
Temporary upload URLs are for model inputs, not permanent asset hosting.

Complete SDK Smoke Test

Save this as crazyrouter-sdk-smoke.mjs:
Run it:
A successful test should verify:
  • models.list returns the available model count
  • chat.completions.create returns text
  • chat.completions.stream receives streamed text
  • embeddings.create returns an embedding vector
  • /v1/video/query returns a task-not-found or other business status, which confirms the native async query route exists

Troubleshooting