Artisanal Futures
AI Agent

API Documentation for Upcycling AI

tRPC endpoint reference for question mutations and queries on upcycled images

Legacy documentation: this page describes an application that is not maintained in this repository. Content was migrated from the previous docs site and may be outdated.

tRPC Endpoints for Questions

api.question.mutation askQuestion (asks AI questions about an upcycled image)
Input
nametypedata typedescription
questionrequiredstringThe question to ask about the image
imageUrlrequiredstringURL of the upcycled image to ask about
generationIdoptionalstringID of the upcycle generation to associate with
Output
statusdata typeresponse
successobject{ data: { answer: string }, message: "Question answered successfully" }
errorTRPCError{ code: "BAD_REQUEST", message: "Invalid question data" }
errorTRPCError{ code: "UNAUTHORIZED", message: "Not authorized to ask questions" }
Example Client Usage
// Client-side usage
import { api } from "~/trpc/react";

const apiUtils = api.useUtils();

// Using React Query mutation
const askQuestionMutation = api.question.askQuestion.useMutation({
	onSuccess: ({ data }) => setAnswer(data.answer),
	onError: () => toastService.error({ message: "Failed to get answer" }),
	onSettled: () => void apiUtils.refinement.invalidate(),
});

// Example call
const handleAskQuestion = () =>
	askQuestionMutation.mutate({
		imageUrl: upcycleImage,
		question: question,
		generationId: generationId,
	});
api.question.query getQuestions (retrieves questions for a specific generation)
Input
nametypedata typedescription
generationIdrequiredstringID of the upcycle generation to query for
Output
statusdata typeresponse
successarrayArray of question objects with their responses, sorted by newest first
errorTRPCError{ code: "BAD_REQUEST", message: "Invalid generation ID" }
errorTRPCError{ code: "UNAUTHORIZED", message: "Not authorized to view questions" }
Example Client Usage
// Client-side usage
import { api } from "~/trpc/react";

// Using React Query hook
const getQuestions = api.question.getQuestions.useQuery(generationId, {
	enabled: !!generationId,
});

// Accessing the data
return (
	<div>
		{getQuestions?.isPending ? (
			<Spinner />
		) : getQuestions?.data?.length > 0 ? (
			getQuestions?.data?.map((q) => (
				<QuestionCard key={q.id} question={q.question} answer={q.llmResponse} date={q.createdAt} />
			))
		) : (
			<p>No questions asked yet.</p>
		)}
	</div>
);

On this page