import { useMemo, type FormEvent } from 'react'; import type { GatewayTask } from '@easyai-ai-gateway/contracts'; import { BookOpen, Play, Search, Send } from 'lucide-react'; import { Badge, Button, Select, Textarea } from '../components/ui'; import type { ApiDocSection, LoadState, TaskForm } from '../types'; const docs: Array<{ key: ApiDocSection; group: string; method: string; path: string; title: string }> = [ { key: 'chat', group: '聊天(Chat)', method: 'POST', path: '/v1/chat/completions', title: 'Chat(聊天)' }, { key: 'imageGeneration', group: '图片', method: 'POST', path: '/v1/images/generations', title: '创建图片' }, { key: 'imageEdit', group: '图片', method: 'POST', path: '/v1/images/edits', title: '编辑图片' }, { key: 'pricing', group: '计费', method: 'POST', path: '/api/v1/pricing/estimate', title: '价格预估' }, { key: 'files', group: '文件', method: 'POST', path: '/v1/files/upload', title: '上传文件' }, ]; const guideItems = ['获取 Base URL 和 API Key', '通知设置-WebHook 参数介绍', '错误码', '测试模式']; const taskKindOptions = [ ['chat.completions', 'Chat'], ['images.generations', '生图'], ['images.edits', '图像编辑'], ] as const; export function ApiDocsPage(props: { activeDocSection: ApiDocSection; apiKeySecret: string; canRun: boolean; coreMessage: string; coreState: LoadState; taskForm: TaskForm; taskResult: GatewayTask | null; onLogin: () => void; onDocSectionChange: (value: ApiDocSection) => void; onSubmitTask: (event: FormEvent) => void; onTaskFormChange: (value: TaskForm) => void; }) { const current = docs.find((item) => item.key === props.activeDocSection) ?? docs[0]; const bodyExample = useMemo(() => requestBodyExample(props.taskForm), [props.taskForm]); function handleSubmit(event: FormEvent) { if (!props.canRun) { event.preventDefault(); props.onLogin(); return; } props.onSubmitTask(event); } return (

{current.group}

{current.title}

{current.method} {current.path}

保持与原 integration-platform / OpenAI 兼容接口一致,支持本地 API Key 和 server-main 接入 token。

Header 参数

Body 参数

application/json