# OpenAI-compatible API docs and Claude relay guide

KaiyunCode docs for OpenAI-compatible APIs, Claude relay, Gemini, image generation, and video generation. Configure the base URL, API key, model, and examples.

Canonical: https://kaiyuncode.com/docs
Markdown: https://kaiyuncode.com/docs.en.md

## Agent setup

KaiyunCode provides an OpenAI-compatible API, an Anthropic Messages-compatible API, image generation, video generation, and client setup guides. An agent can get the base URL, authentication, common endpoints, examples, and troubleshooting from this page.

OpenAI-compatible SDKs, Codex CLI, and most proxy tools use https://kaiyuncode.com/v1. The Anthropic SDK and Claude Code use https://kaiyuncode.com, without /v1.

- OpenAI-compatible base URL: https://kaiyuncode.com/v1
- Anthropic / Claude Code base URL: https://kaiyuncode.com
- Authentication: Authorization: Bearer <API key>
- Create the API key in KaiyunCode, then replace APIKEY or REPLACE_WITH_YOUR_API_KEY in the examples.
- Use a model name that is enabled on the KaiyunCode model pricing page.

## Common endpoints

Start with the endpoints below. Synchronous endpoints return the result directly. Asynchronous endpoints return a task_id or id, which you then poll.

- POST /v1/chat/completions: OpenAI Chat Completions, for existing projects, multi-turn chat, and Gemini image-compatible calls.
- POST /v1/responses: OpenAI Responses, for newer OpenAI SDKs, Codex CLI, and tool-call flows.
- POST /v1/messages: Anthropic Messages, for Claude models and Claude Code.
- POST /v1/images/async/generations: submit an async text-to-image task.
- POST /v1/images/async/edits: submit an async image-edit task with multipart/form-data.
- GET /v1/images/async/{taskId}: poll an image task.
- POST /v1/videos: submit a video generation or continuation task.
- GET /v1/videos/{taskId}: poll a video task and read the result URL.

## Chat Completions example

An existing OpenAI-compatible project usually only needs a new base URL and API key. Put the user input in messages, and use a model name that is enabled on KaiyunCode.

### curl

```bash
curl https://kaiyuncode.com/v1/chat/completions \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4-mini-plus",
    "messages": [
      { "role": "user", "content": "Hello, please help me analyze this project" }
    ]
  }'
```

## Responses example

The Responses API fits new projects and newer OpenAI clients such as Codex. Set apiKey to your KaiyunCode API key and baseURL to https://kaiyuncode.com/v1.

### Node.js

```javascript
import OpenAI from "openai"

const client = new OpenAI({
  apiKey: "***",
  baseURL: "https://kaiyuncode.com/v1"
})

const response = await client.responses.create({
  model: "gpt-5.4-mini-plus",
  input: "Hello, give me a short product selling point"
})

console.log(response.output_text)
```

## Anthropic Messages example

Claude models use the Anthropic Messages format. The Anthropic SDK base_url is the site root. Do not append /v1.

### Python

```python
from anthropic import Anthropic

client = Anthropic(
    api_key="APIKEY",
    base_url="https://kaiyuncode.com"
)

message = client.messages.create(
    model="claude-opus-4-7",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Hello, give me a short product selling point"}
    ],
)

print(message.content[0].text)
```

## Gemini image example

Gemini image generation and edits use /v1/chat/completions. Put the text and reference images in messages[0].content. Put size and aspect ratio in extra_body.google.image_config.

### Text to image

```bash
curl https://kaiyuncode.com/v1/chat/completions \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3.1-flash-image",
    "temperature": 0.8,
    "extra_body": {
      "google": {
        "image_config": {
          "image_size": "1K",
          "aspect_ratio": "1:1"
        }
      }
    },
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "Generate a main e-commerce product image of a scented candle with warm studio lighting, a clean background, and the product centered."
          }
        ]
      }
    ]
  }'
```

## GPT Image 2 async example

GPT Image 2 text-to-image and image-edit calls are asynchronous. Read task_id from the submit response, then poll /v1/images/async/{taskId}.

### Submit a text-to-image task

```bash
curl https://kaiyuncode.com/v1/images/async/generations \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "Generate a main e-commerce product image of a sports water bottle on a white background, realistic photography, centered subject, and soft shadow.",
    "size": "1024x1024",
    "quality": "high",
    "background": "opaque",
    "output_format": "png",
    "n": 1
  }'
```

### Poll the image task

```bash
curl https://kaiyuncode.com/v1/images/async/TASK_ID \
  -H "Authorization: Bearer ***"
```

## Video example

Submit video tasks to /v1/videos. Poll /v1/videos/{taskId} with the returned id or task_id. When it finishes, read video_url, media_url, result_url, metadata.url, or results[0].url.

Flow VEO and Omni use the same /v1/videos entry. VEO is fixed at 8 seconds and 720p; do not send duration. Omni duration is only 4, 6, 8, or 10, and aspect_ratio is only 16:9 or 9:16. omni_video_edit requires a video_url of at most 30 seconds, plus one text item and up to five reference images in messages.content. Optional generationConfig.videoConfig.aspectRatio is only 16:9 or 9:16; do not send duration.

### Submit a task

```bash
curl https://kaiyuncode.com/v1/videos \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "sora-v3-fast",
    "prompt": "An orange cat lazily grooming itself on a windowsill, slow motion, cinematic",
    "duration": 5,
    "aspect_ratio": "16:9"
  }'
```

### Flow VEO text to video

```bash
curl https://kaiyuncode.com/v1/videos \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "veo_3_1_t2v_fast",
    "prompt": "A coastline at dawn, cinematic aerial shot, camera slowly pushing in",
    "resolution": "720p"
  }'
```

### Flow Omni text to video

```bash
curl https://kaiyuncode.com/v1/videos \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "omni",
    "prompt": "A neon street after rain, camera moving steadily forward",
    "duration": 8,
    "aspect_ratio": "16:9"
  }'
```

### Poll the task

```bash
curl https://kaiyuncode.com/v1/videos/TASK_ID \
  -H "Authorization: Bearer ***"
```

## Troubleshooting

- 401 or Unauthorized: check that the API key was copied completely and sent as Authorization: Bearer. For Claude Code, also confirm ANTHROPIC_AUTH_TOKEN was written.
- Model not found or unavailable: change model to a name that is enabled on the KaiyunCode pricing page.
- Anthropic SDK failure: base_url must be https://kaiyuncode.com, not https://kaiyuncode.com/v1.
- OpenAI SDK failure: baseURL must be https://kaiyuncode.com/v1, and the SDK must support the endpoint you are calling.
- Async task never finishes: poll every 3-5 seconds, and read the result URL only when the status is completed, succeeded, or success.
- Temporary media URL expired: download or copy the file to your own storage soon after generation succeeds.
