Aihubmix 프로바이더

Aihubmix 프로바이더

Aihubmix 프로바이더는 Aihubmix API를 통해 OpenAI, Anthropic Claude, Google Gemini 모델을 포함한 여러 AI 프로바이더에 대한 통합 접근을 제공해요. 사용 가능한 모든 모델은 aihubmix.com/models에서 확인할 수 있어요.

출처: 문서

본문

설정 (Setup)

Aihubmix 프로바이더는 @aihubmix/ai-sdk-provider 모듈에서 사용할 수 있어요. 다음과 같이 설치할 수 있어요:

프로바이더 인스턴스 (Provider Instance)

방법 1: createAihubmix 사용

Aihubmix 프로바이더 인스턴스를 만들려면 createAihubmix 함수를 사용하세요:

import { createAihubmix } from '@aihubmix/ai-sdk-provider';

const aihubmix = createAihubmix({
  apiKey: 'AIHUB...EY',
});

Aihubmix API 키는 Aihubmix Keys에서 얻을 수 있어요.

방법 2: 환경 변수 사용

또는 AIHUBMIX_API_KEY 환경 변수를 설정해 미리 구성된 aihubmix 인스턴스를 사용할 수 있어요:

# .env
AIHUBMIX_API_KEY=your_api_key_here

그런 다음 미리 구성된 인스턴스를 가져와 사용하세요:

import { aihubmix } from '@aihubmix/ai-sdk-provider';

사용법 (Usage)

채팅 완성 (Chat Completion)

import { aihubmix } from '@aihubmix/ai-sdk-provider';
import { generateText } from 'ai';

const { text } = await generateText({
  model: aihubmix('o4-mini'),
  prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});

Claude 모델 (Claude Model)

import { aihubmix } from '@aihubmix/ai-sdk-provider';
import { generateText } from 'ai';

const { text } = await generateText({
  model: aihubmix('claude-sonnet-4-5-20250929'),
  prompt: 'Explain quantum computing in simple terms.',
});

Gemini 모델 (Gemini Model)

import { aihubmix } from '@aihubmix/ai-sdk-provider';
import { generateText } from 'ai';

const { text } = await generateText({
  model: aihubmix('gemini-2.5-flash'),
  prompt: 'Create a Python script to sort a list of numbers.',
});

이미지 생성 (Image Generation)

import { aihubmix } from '@aihubmix/ai-sdk-provider';
import { generateImage } from 'ai';

const { image } = await generateImage({
  model: aihubmix.image('gpt-image-1'),
  prompt: 'A beautiful sunset over mountains',
});

임베딩 (Embeddings)

import { aihubmix } from '@aihubmix/ai-sdk-provider';
import { embed } from 'ai';

const { embedding } = await embed({
  model: aihubmix.embedding('text-embedding-ada-002'),
  value: 'Hello, world!',
});

전사 (Transcription)

import { aihubmix } from '@aihubmix/ai-sdk-provider';
import { transcribe } from 'ai';

const { text } = await transcribe({
  model: aihubmix.transcription('whisper-1'),
  audio: audioFile,
});

텍스트 스트리밍 (Stream Text)

import { aihubmix } from '@aihubmix/ai-sdk-provider';
import { streamText } from 'ai';

const result = streamText({
  model: aihubmix('gpt-3.5-turbo'),
  prompt: 'Write a short story about a robot learning to paint.',
  maxOutputTokens: 256,
  temperature: 0.3,
  maxRetries: 3,
});

let fullText = '';
for await (const textPart of result.textStream) {
  fullText += textPart;
  process.stdout.write(textPart);
}

console.log('\nUsage:', await result.usage);
console.log('Finish reason:', await result.finishReason);

구조화된 출력 (Structured Output)

import { aihubmix } from '@aihubmix/ai-sdk-provider';
import { generateText, Output } from 'ai';
import { z } from 'zod';

const result = await generateText({
  model: aihubmix('gpt-4o-mini'),
  output: Output.object({
    schema: z.object({
      recipe: z.object({
        name: z.string(),
        ingredients: z.array(
          z.object({
            name: z.string(),
            amount: z.string(),
          }),
        ),
        steps: z.array(z.string()),
      }),
    }),
  }),
  prompt: 'Generate a lasagna recipe.',
});

console.log(JSON.stringify(result.output.recipe, null, 2));
console.log('Token usage:', result.usage);
console.log('Finish reason:', result.finishReason);

구조화된 출력 스트리밍 (Streaming Structured Output)

import { aihubmix } from '@aihubmix/ai-sdk-provider';
import { streamText, Output } from 'ai';
import { z } from 'zod';

const result = streamText({
  model: aihubmix('gpt-4o-mini'),
  output: Output.object({
    schema: z.object({
      recipe: z.object({
        name: z.string(),
        ingredients: z.array(
          z.object({
            name: z.string(),
            amount: z.string(),
          }),
        ),
        steps: z.array(z.string()),
      }),
    }),
  }),
  prompt: 'Generate a lasagna recipe.',
});

for await (const objectPart of result.partialOutputStream) {
  console.log(objectPart);
}

console.log('Token usage:', await result.usage);
console.log('Final object:', await result.output);

다중 임베딩 (Embed Many)

import { aihubmix } from '@aihubmix/ai-sdk-provider';
import { embedMany } from 'ai';

const { embeddings, usage } = await embedMany({
  model: aihubmix.embedding('text-embedding-3-small'),
  values: [
    'sunny day at the beach',
    'rainy afternoon in the city',
    'snowy night in the mountains',
  ],
});

console.log('Embeddings:', embeddings);
console.log('Usage:', usage);

음성 합성 (Speech Synthesis)

import { aihubmix } from '@aihubmix/ai-sdk-provider';
import { generateSpeech } from 'ai';

const { audio } = await generateSpeech({
  model: aihubmix.speech('tts-1'),
  text: 'Hello, this is a test for speech synthesis.',
});

툴 (Tools)

Aihubmix 프로바이더는 웹 검색을 포함한 다양한 툴을 지원해요:

import { aihubmix } from '@aihubmix/ai-sdk-provider';
import { generateText } from 'ai';

const { text } = await generateText({
  model: aihubmix('gpt-5'),
  prompt: 'What are the latest developments in AI?',
  tools: {
    webSearchPreview: aihubmix.tools.webSearch({
      searchContextSize: 'high',
    }),
  },
});

추가 리소스 (Additional Resources)

더 알아보기 (Learn more)

전체 사이트맵