AI Vision Support

Enable your app to understand and analyze images using FreeToken's vision-capable AI models.

Overview

FreeToken supports multi-modal AI models that can process both text and images. Right now, the FreeToken SDK only supports vision for cloud versions of models. Local vision support is coming soon. If the runLocation is set to .automatic or .cloud, and the selected model supports vision, the SDK will automatically send your AI vision request to the cloud for processing.

Quick Start

Here's the simplest way to analyze an image:

import FreeToken

// 1. Prepare your image
let imageData = UIImage(named: "photo")!.pngData()!
let attachment = FreeToken.MessageAttachment.image(imageData, filename: "photo.png")

// 2. Create a message thread
FreeToken.shared.createMessageThread(
    success: { thread in
        print("Created thread with ID: \(thread.id)")
        addImageMessage(to: thread.id)
    },
    error: { err in
        print("Error creating thread: \(err.localizedDescription)")
    }
)

// 3. Add your message to the thread
func addImageMessage(to threadId: String) {
    let message = FreeToken.Message(
        role: .user,
        content: "What's in this image?",
        attachments: [attachment]
    )

    FreeToken.shared.addMessageToThread(
        id: threadId,
        message: message,
        success: { message in
            print("Added message with ID: \(message.id)")
            runVisionModel(on: threadId)
        },
        error: { err in
            print("Error adding message: \(err.localizedDescription)")
        }
    )
}

// 3. Send to vision model
func runVisionModel(on threadId: String) {
    FreeToken.shared.runMessageThread(
        threadId: threadId,
        modelCode: "llama_4_scout_cloud", // Use a vision-capable model
        success: { response in
            print("AI Response: \(response.content)")
        },
        error: { err in
            print("Error during chat: \(err.localizedDescription)")
        }
    )
}

Multiple Images

FreeToken supports sending multiple images in a single message. Just add more attachments to the attachments array when creating your message.

Supported Image Formats

FreeToken supports common image formats such as PNG & JPEG. Make sure your images are not excessively large to ensure optimal performance of the AI models.