{"record":{"id":"2cef19ff4b7563b7","repo":"FoundationAgents/MetaGPT","slug":"missing-necessary-parameters","errorCode":null,"errorMessage":"Missing necessary parameters.","messagePattern":"Missing necessary parameters\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"metagpt/learn/text_to_image.py","lineNumber":38,"sourceCode":"async def text_to_image(text, size_type: str = \"512x512\", config: Optional[Config] = None):\n    \"\"\"Text to image\n\n    :param text: The text used for image conversion.\n    :param size_type: If using OPENAI, the available size options are ['256x256', '512x512', '1024x1024'], while for MetaGPT, the options are ['512x512', '512x768'].\n    :param config: Config\n    :return: The image data is returned in Base64 encoding.\n    \"\"\"\n    config = config if config else Config.default()\n    image_declaration = \"data:image/png;base64,\"\n\n    model_url = config.metagpt_tti_url\n    if model_url:\n        binary_data = await oas3_metagpt_text_to_image(text, size_type, model_url)\n    elif config.get_openai_llm():\n        llm = LLM(llm_config=config.get_openai_llm())\n        binary_data = await oas3_openai_text_to_image(text, size_type, llm=llm)\n    else:\n        raise ValueError(\"Missing necessary parameters.\")\n    base64_data = base64.b64encode(binary_data).decode(\"utf-8\")\n\n    s3 = S3(config.s3)\n    url = await s3.cache(data=base64_data, file_ext=\".png\", format=BASE64_FORMAT)\n    if url:\n        return f\"![{text}]({url})\"\n    return image_declaration + base64_data if base64_data else \"\"\n","sourceCodeStart":20,"sourceCodeEnd":46,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/learn/text_to_image.py#L20-L46","documentation":"text_to_image requires either a MetaGPT text-to-image endpoint (config.metagpt_tti_url) or an OpenAI LLM configuration (config.get_openai_llm()); if both are absent it raises ValueError('Missing necessary parameters.'), because there is no provider left to generate the image.","triggerScenarios":"Calling text_to_image/promote() when neither METAGPT_TTI_URL is set nor a valid OpenAI model entry (api key etc.) exists in the LLM configuration.","commonSituations":"Running agents with non-OpenAI providers only (e.g. Azure/Anthropic entries) and then triggering an action that renders an image; missing env vars METAGPT_TTI_URL / OPENAI_API_KEY in deployment; config2.yaml not enabling the openai entry.","solutions":["Set config.metagpt_tti_url (env METAGPT_TTI_URL) to a MetaGPT text-to-image service endpoint.","Or add a valid OpenAI entry to the LLM config so config.get_openai_llm() returns one.","If image generation is optional for your agent, disable the actions that call promote()/text_to_image."],"exampleFix":"# before: no TTI url, no openai entry -> ValueError\n# after (option 1)\nexport METAGPT_TTI_URL=\"https://your-tti-service/api\"\n# after (option 2, config2.yaml)\nllm:\n  api_type: openai\n  base_url: https://api.openai.com/v1\n  api_key: YOUR_KEY\n  model: gpt-4o-mini","handlingStrategy":"validation","validationCode":"from metagpt.config2 import config\n\ndef tti_available() -> bool:\n    return bool(config.metagpt_tti_url) or bool(config.get_openai_llm())\n\nif not tti_available():\n    disable_image_actions = True","typeGuard":null,"tryCatchPattern":"try:\n    md = await text_to_image(prompt)\nexcept ValueError as e:\n    if \"Missing necessary parameters\" in str(e):\n        md = prompt  # degrade to plain text instead of crashing the agent\n    else:\n        raise","preventionTips":["Feature-detect image support at startup and disable TTI actions when absent.","Document required env (METAGPT_TTI_URL or OpenAI) next to any image-generating action."],"tags":["text-to-image","configuration","missing-provider"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}