{"_id":"@55387.ai/uniapi-sdk","name":"@55387.ai/uniapi-sdk","dist-tags":{"latest":"0.1.8"},"versions":{"0.1.8":{"name":"@55387.ai/uniapi-sdk","version":"0.1.8","description":"TypeScript SDK for One API - unified AI client with OpenAI-compatible interface","type":"module","main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"keywords":["ai","sdk","client","openai","anthropic","claude","gemini","llm","api","chat","streaming","typescript"],"author":{"name":"One API Contributors"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/one-api/one.git","directory":"packages/sdk"},"homepage":"https://github.com/one-api/one#readme","bugs":{"url":"https://github.com/one-api/one/issues"},"publishConfig":{"access":"public"},"sideEffects":false,"dependencies":{},"devDependencies":{"@types/node":"^20.10.0","@vitest/coverage-v8":"^1.0.0","typescript":"^5.3.0","vitest":"^1.0.0"},"peerDependencies":{"typescript":">=5.0.0"},"peerDependenciesMeta":{"typescript":{"optional":true}},"engines":{"node":">=18.0.0"},"scripts":{"build":"tsc","dev":"tsc --watch","test":"vitest run","test:watch":"vitest","test:coverage":"vitest run --coverage","clean":"rm -rf dist"},"_id":"@55387.ai/uniapi-sdk@0.1.8","_integrity":"sha512-q0TCIS8pL1ZzjodfTxookxWXsbM6y0j7VoQa/tuz+OseyhYViw8IOeWxPxOIdE1mMlvbfvrH+sAHy/SSOnPKJA==","_resolved":"/private/var/folders/4c/_zgqmwls3fdc_qv864lnqcbm0000gn/T/400ef149cee60266a76d0a7739abb60f/55387.ai-uniapi-sdk-0.1.8.tgz","_from":"file:55387.ai-uniapi-sdk-0.1.8.tgz","_nodeVersion":"25.2.1","_npmVersion":"11.6.2","dist":{"integrity":"sha512-q0TCIS8pL1ZzjodfTxookxWXsbM6y0j7VoQa/tuz+OseyhYViw8IOeWxPxOIdE1mMlvbfvrH+sAHy/SSOnPKJA==","shasum":"7790b5b1fc0ed0b2cc866b9136bd7004f8e3a4a8","tarball":"https://registry.npmjs.org/@55387.ai/uniapi-sdk/-/uniapi-sdk-0.1.8.tgz","fileCount":19,"unpackedSize":45981,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDxbLGk3tALsVHZDXZNdKGC4f2CXKhAcuHiNsOLwnmgpQIhAJax1zyQm9Y3OUxulZUC1diaVfgc25HDdhwnQrHjp66K"}]},"_npmUser":{"name":"rosslin","email":"atai829525@gmail.com"},"directories":{},"maintainers":[{"name":"rosslin","email":"atai829525@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/uniapi-sdk_0.1.8_1766540873988_0.7858439792463352"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-24T01:47:53.927Z","0.1.8":"2025-12-24T01:47:54.124Z","modified":"2025-12-24T01:47:54.436Z"},"maintainers":[{"name":"rosslin","email":"atai829525@gmail.com"}],"description":"TypeScript SDK for One API - unified AI client with OpenAI-compatible interface","homepage":"https://github.com/one-api/one#readme","keywords":["ai","sdk","client","openai","anthropic","claude","gemini","llm","api","chat","streaming","typescript"],"repository":{"type":"git","url":"git+https://github.com/one-api/one.git","directory":"packages/sdk"},"author":{"name":"One API Contributors"},"bugs":{"url":"https://github.com/one-api/one/issues"},"license":"MIT","readme":"# @55387.ai/uniapi-sdk\n\nTypeScript SDK for One API - Unified AI client with OpenAI-compatible interface.\n\n## Installation\n\n```bash\nnpm install @55387.ai/uniapi-sdk\n# or\npnpm add @55387.ai/uniapi-sdk\n# or\nyarn add @55387.ai/uniapi-sdk\n```\n\n## Quick Start\n\n```typescript\nimport { OneClient } from '@55387.ai/uniapi-sdk';\n\nconst client = new OneClient({\n  apiKey: 'your-api-key',\n  baseUrl: 'https://your-one-api-server.com', // or http://localhost:3000 for local\n});\n\n// Simple chat completion\nconst response = await client.chat.completions.create({\n  model: 'gpt-4',\n  messages: [{ role: 'user', content: 'Hello!' }],\n});\n\nconsole.log(response.choices[0].message.content);\n```\n\n## API Reference\n\n### OneClient\n\nThe main client class for interacting with One API.\n\n#### Constructor Options\n\n```typescript\ninterface OneClientOptions {\n  apiKey: string;           // Your API key\n  baseUrl?: string;         // API server URL (default: http://localhost:3000)\n  timeout?: number;         // Request timeout in ms (default: 60000)\n  maxRetries?: number;      // Max retry attempts (default: 3)\n}\n```\n\n### Chat Completions\n\n#### Non-streaming\n\n```typescript\nconst response = await client.chat.completions.create({\n  model: 'gpt-4',\n  messages: [\n    { role: 'system', content: 'You are a helpful assistant.' },\n    { role: 'user', content: 'Hello!' }\n  ],\n  temperature: 0.7,\n  max_tokens: 1000,\n});\n\nconsole.log(response.choices[0].message.content);\n```\n\n#### Streaming\n\n```typescript\nconst stream = await client.chat.completions.create({\n  model: 'claude-3-sonnet',\n  messages: [{ role: 'user', content: 'Tell me a story' }],\n  stream: true,\n});\n\nfor await (const chunk of stream) {\n  process.stdout.write(chunk.choices[0]?.delta?.content || '');\n}\n```\n\n### Multimodal Support\n\n#### Text and Images\n\n```typescript\nimport { imageUrl, imageBase64, text } from '@55387.ai/uniapi-sdk';\n\nconst response = await client.chat.completions.create({\n  model: 'gpt-4o',\n  messages: [{\n    role: 'user',\n    content: [\n      text('What do you see in this image?'),\n      imageUrl('https://example.com/image.jpg'),\n    ],\n  }],\n});\n```\n\n#### Base64 Images\n\n```typescript\nconst response = await client.chat.completions.create({\n  model: 'gemini-2.5-flash',\n  messages: [{\n    role: 'user',\n    content: [\n      text('Describe this image'),\n      imageBase64(base64Data, 'image/png'),\n    ],\n  }],\n});\n```\n\n### Advanced Features\n\n#### Thinking Mode (DeepSeek R1, Claude 3.7+)\n\n```typescript\nconst response = await client.chat.completions.create({\n  model: 'claude-3-7-sonnet',\n  messages: [{ role: 'user', content: 'Solve this complex math problem...' }],\n  thinking: {\n    type: 'enabled',\n    budget_tokens: 2048\n  }\n});\n\n// Access thinking process\nconsole.log('Thinking:', response.choices[0].message.reasoning_content);\nconsole.log('Answer:', response.choices[0].message.content);\n```\n\n#### Function Calling (Tool Use)\n\n```typescript\nconst tools = [{\n  type: 'function',\n  function: {\n    name: 'get_weather',\n    description: 'Get current weather information',\n    parameters: {\n      type: 'object',\n      properties: {\n        location: { type: 'string', description: 'City name' }\n      },\n      required: ['location']\n    }\n  }\n}];\n\nconst response = await client.chat.completions.create({\n  model: 'gpt-4o',\n  messages: [{ role: 'user', content: 'What\\'s the weather in Beijing?' }],\n  tools: tools,\n});\n\n// Check for tool calls\nif (response.choices[0].message.tool_calls) {\n  const toolCall = response.choices[0].message.tool_calls[0];\n  console.log('Function:', toolCall.function.name);\n  console.log('Args:', JSON.parse(toolCall.function.arguments));\n}\n```\n\n### Streaming Chat Helper\n\nFor easier streaming chat management:\n\n```typescript\nconst chat = client.createStreamingChat({\n  model: 'gemini-1.5-pro',\n  systemPrompt: 'You are a helpful assistant.',\n});\n\nawait chat.send('Hello!', {\n  onContent: (content) => process.stdout.write(content),\n  onComplete: (fullContent) => console.log('\\n--- Complete ---'),\n  onError: (error) => console.error('Error:', error),\n});\n```\n\n### Error Handling\n\n```typescript\ntry {\n  const response = await client.chat.completions.create({\n    model: 'gpt-4',\n    messages: [{ role: 'user', content: 'Hello!' }],\n  });\n} catch (error) {\n  if (error.status === 401) {\n    console.error('Invalid API key');\n  } else if (error.status === 429) {\n    console.error('Rate limit exceeded');\n  } else {\n    console.error('API error:', error.message);\n  }\n}\n```\n\n## Supported Models\n\nThe SDK automatically routes to the appropriate provider based on model name:\n\n| Provider | Model Prefixes | Example Models |\n|----------|----------------|----------------|\n| OpenAI | `gpt-*`, `o1*` | `gpt-4`, `gpt-3.5-turbo` |\n| Anthropic | `claude-*` | `claude-3-sonnet`, `claude-3-haiku` |\n| Google Gemini | `gemini-*` | `gemini-1.5-pro`, `gemini-2.0-flash` |\n| DeepSeek | `deepseek-*` | `deepseek-chat`, `deepseek-reasoner` |\n| 通义千问 | `qwen*` | `qwen-turbo`, `qwen-max` |\n| 智谱 GLM | `glm-*`, `codegeex-*` | `glm-4`, `codegeex-2` |\n| Kimi | `kimi-*`, `moonshot-*` | `kimi-latest` |\n\n## TypeScript Support\n\nThe SDK is written in TypeScript and provides full type safety:\n\n```typescript\nimport type { ChatCompletionMessageParam, ChatCompletionCreateParams } from '@55387.ai/uniapi-sdk';\n\n// All parameters are fully typed\nconst params: ChatCompletionCreateParams = {\n  model: 'gpt-4',\n  messages: [{ role: 'user', content: 'Hello!' }],\n  temperature: 0.7,\n};\n```\n\n## License\n\nMIT","readmeFilename":"README.md","_rev":"1-6eb924b9419b218957a3f50b6357fa4e"}