Skip to main content
Glama

kobold_txt2img

Generate images from text descriptions using Stable Diffusion. Provide a text prompt to create custom visuals for projects, content, or creative exploration.

Instructions

Generate image from text prompt

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
apiUrlNohttp://localhost:5001
promptYes
negative_promptNo
widthNo
heightNo
stepsNo
cfg_scaleNo
sampler_nameNo
seedNo

Implementation Reference

  • Zod schema defining the input parameters for the kobold_txt2img tool, including prompt, dimensions, steps, etc., extending the base config schema.
    const Txt2ImgSchema = BaseConfigSchema.extend({
        prompt: z.string(),
        negative_prompt: z.string().optional(),
        width: z.number().optional(),
        height: z.number().optional(),
        steps: z.number().optional(),
        cfg_scale: z.number().optional(),
        sampler_name: z.string().optional(),
        seed: z.number().optional(),
    });
  • src/index.ts:244-248 (registration)
    Registration of the kobold_txt2img tool in the list of available tools returned by ListToolsRequest.
    {
        name: "kobold_txt2img",
        description: "Generate image from text prompt",
        inputSchema: zodToJsonSchema(Txt2ImgSchema),
    },
  • Core handler logic for executing POST endpoint tools, including kobold_txt2img: parses arguments, proxies POST request to KoboldAI Stable Diffusion API endpoint, returns JSON response.
    if (postEndpoints[name]) {
        const { endpoint, schema } = postEndpoints[name];
        const parsed = schema.safeParse(args);
        if (!parsed.success) {
            throw new Error(`Invalid arguments: ${parsed.error}`);
        }
    
        const result = await makeRequest(`${apiUrl}${endpoint}`, 'POST', requestData);
        return {
            content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
            isError: false,
        };
  • Specific endpoint configuration for kobold_txt2img tool within the postEndpoints mapping used by the generic handler.
    kobold_txt2img: { endpoint: '/sdapi/v1/txt2img', schema: Txt2ImgSchema },
  • Utility function for making HTTP requests to the KoboldAI API, used by all tool handlers including kobold_txt2img.
    async function makeRequest(url: string, method = 'GET', body: Record<string, unknown> | null = null) {
        const options: RequestInit = {
            method,
            headers: body ? { 'Content-Type': 'application/json' } : undefined,
        };
        
        if (body && method !== 'GET') {
            options.body = JSON.stringify(body);
        }
    
        const response = await fetch(url, options);
        if (!response.ok) {
            throw new Error(`KoboldAI API error: ${response.statusText}`);
        }
        
        return response.json();
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/PhialsBasement/KoboldCPP-MCP-Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server