Skip to main content

AI Kit Vue

Vue 3 composables for building AI-powered interfaces with streaming support, built on @ainative/ai-kit-core.

npm install @ainative/ai-kit-vue

Requires: Vue 3 (vue@^3.0.0)

Composables

useAIStream

Stream AI completions with reactive state for messages, streaming status, errors, and token usage.

<script setup lang="ts">
import { useAIStream } from '@ainative/ai-kit-vue';

const { messages, isStreaming, error, send, reset, retry, stop, usage } =
useAIStream({
apiUrl: 'https://api.ainative.studio/api/v1/chat/completions',
apiKey: import.meta.env.VITE_AINATIVE_API_KEY,
model: 'gpt-oss-120b',
});
</script>

<template>
<div>
<div v-for="m in messages" :key="m.id">{{ m.role }}: {{ m.content }}</div>
<p v-if="isStreaming">…</p>
<p v-if="error" class="error">{{ error.message }}</p>
<button @click="send('Hello!')" :disabled="isStreaming">Send</button>
<button @click="stop" v-if="isStreaming">Stop</button>
</div>
</template>

config is a StreamConfig from @ainative/ai-kit-core (API URL, key, model, and generation options).

Returns (UseAIStreamResult):

FieldTypeDescription
messagesShallowRef<Message[]>Conversation messages (reactive)
isStreamingShallowRef<boolean>Whether a response is currently streaming
errorShallowRef<Error | null>Last error, if any
usageShallowRef<Usage>Token usage for the stream
send(content)(string) => Promise<void>Send a user message and stream the reply
retry()() => Promise<void>Re-run the last send
stop()() => voidAbort the in-flight stream
reset()() => voidClear messages and state

useConversation

Persist and load a conversation (via a ZeroDB-backed store), with optional auto-save and pagination.

<script setup lang="ts">
import { useConversation } from '@ainative/ai-kit-vue';
import { store } from './store'; // your ai-kit-core conversation store

const convo = useConversation({
store,
conversationId: 'thread-123',
autoSave: true,
autoSaveDelay: 1000,
pageSize: 50,
autoLoad: true,
onLoad: (c) => console.log('loaded', c.messages.length),
onError: (e) => console.error(e),
});
</script>

Options (UseConversationOptions):

OptionTypeDescription
storestoreConversation store to read/write
conversationIdstringID of the conversation to load/persist
autoSavebooleanPersist changes automatically
autoSaveDelaynumberDebounce (ms) before auto-saving
pageSizenumberMessages per page when loading
autoLoadbooleanLoad on mount
ttlnumberCache TTL
metadataRecord<string, any>Arbitrary conversation metadata
onLoad / onSave / onErrorcallbacksLifecycle hooks

See also