{"record":{"id":"f59e310ad40cec73","repo":"agentscope-ai/agentscope","slug":"gemini-embedding-api-requires-inline-data-base64s","errorCode":null,"errorMessage":"Gemini embedding API requires inline data (Base64Source). URLSource is not directly supported for embedding. Got URL: {source.url}","messagePattern":"Gemini embedding API requires inline data \\(Base64Source\\)\\. URLSource is not directly supported for embedding\\. Got URL: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agentscope/embedding/_gemini/_model.py","lineNumber":476,"sourceCode":"        \"\"\"\n        from google.genai import types\n        from ...message import Base64Source, URLSource\n\n        source = block.source\n\n        if isinstance(source, Base64Source):\n            import base64\n\n            return types.Part.from_bytes(\n                data=base64.b64decode(source.data),\n                mime_type=source.media_type,\n            )\n\n        if isinstance(source, URLSource):\n            # Gemini SDK doesn't have a direct from_url for\n            # embed_content; download or use File API.\n            # For now, raise — callers should use Base64Source.\n            raise ValueError(\n                \"Gemini embedding API requires inline data \"\n                \"(Base64Source). URLSource is not directly supported \"\n                f\"for embedding. Got URL: {source.url}\",\n            )\n\n        raise ValueError(\n            f\"Unsupported source type {type(source).__name__} \"\n            f\"in DataBlock.\",\n        )\n","sourceCodeStart":458,"sourceCodeEnd":486,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/embedding/_gemini/_model.py#L458-L486","documentation":"Gemini's embed_content API only accepts inline (base64) content, so the wrapper rejects DataBlocks whose source is a URLSource. The message is deliberate: the SDK has no from_url path for embeddings, so callers must inline the bytes themselves.","triggerScenarios":"Building DataBlock(source=URLSource(url=\"https://...\", media_type=\"image/png\")) and passing it to the Gemini embedding model; _call_multimodal -> _data_block_to_part hits the URLSource branch and raises.","commonSituations":"Reusing URL-based DataBlocks built for chat/LLM formatters (which do fetch URLs) in an embedding call; storing assets in cloud storage (S3/GCS signed URLs) and trying to embed them directly.","solutions":["Download the URL content and rebuild the DataBlock with Base64Source (inline bytes)","Migrate assets to the Gemini File API and reference them where supported, or pre-cache bytes locally","Centralize a to_base64_block(url) helper so URL blocks never reach the embedding model"],"exampleFix":"# before\nblock = DataBlock(source=URLSource(url=img_url, media_type=\"image/png\"))\nemb = await model(inputs=[block])\n\n# after\nimport requests, base64\nfrom agentscope.message import DataBlock, Base64Source\nraw = requests.get(img_url, timeout=30).content\nblock = DataBlock(source=Base64Source(data=base64.b64encode(raw).decode(), media_type=\"image/png\"))\nemb = await model(inputs=[block])","handlingStrategy":"fallback","validationCode":"from agentscope.message import URLSource\nfor x in inputs:\n    src = getattr(x, \"source\", None)\n    if isinstance(src, URLSource):\n        raise ValueError(\"inline URL blocks before calling gemini embedding\")  # or convert","typeGuard":"from agentscope.message import URLSource\n\ndef has_url_source(inputs: list) -> bool:\n    return any(isinstance(getattr(x, \"source\", None), URLSource) for x in inputs)","tryCatchPattern":"try:\n    emb = await model(inputs=inputs)\nexcept ValueError as e:\n    if \"URLSource is not directly supported\" in str(e):\n        inputs = [inline_url_block(x) if is_url_block(x) else x for x in inputs]\n        emb = await model(inputs=inputs)\n    else:\n        raise","preventionTips":["Convert remote assets to Base64Source before embedding","Keep a shared inline_url(url) helper in your codebase","Remember chat formatters fetch URLs but the embedding API cannot"],"tags":["embedding","gemini","url-source","multimodal"],"backgroundTag":"unsupported-source-type","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}