{"id":"CKUUBgVB","creatorId":"anonymous","title":"Exact Embedder('bedrock:cohere.embed-english-v3') string path (issue #15361; transport stub)","createdAt":1796072363645,"updatedAt":1796072363645,"latestVersionNum":1,"versions":[{"versionNum":1,"version":null,"branchName":null,"branchSha":null,"runRelease":true,"runBranch":false,"sdkDeps":{"pip":["AWS_DEFAULT_REGION set for local boto3 client construction","No AWS credentials/network: invoke_model is patched and never reaches Bedrock","pydantic-ai-slim with bedrock extra"]},"snippets":[{"id":"repro","name":"repro.py","code":"import asyncio, io, json, os\nfrom unittest.mock import patch\nfrom botocore.exceptions import ClientError\nfrom pydantic_ai import Embedder\n\nasync def main():\n    os.environ.setdefault('AWS_DEFAULT_REGION', 'us-east-1')\n    embedder = Embedder('bedrock:cohere.embed-english-v3', defer_model_check=False)\n    model = embedder._get_model()  # access model only to patch its transport seam\n    requests = []\n\n    def invoke_model(*, modelId, body, contentType, accept):\n        payload = json.loads(body)\n        requests.append(payload)\n        texts = payload['texts']\n        if len(texts) > 96:\n            raise ClientError(\n                {'Error': {'Code': 'ValidationException', 'Message': 'Invalid parameter combination. Please check and try again.'},\n                 'ResponseMetadata': {'HTTPStatusCode': 400}},\n                'InvokeModel',\n            )\n        return {\n            'ResponseMetadata': {'HTTPHeaders': {'x-amzn-bedrock-input-token-count': str(len(texts))}},\n            'body': io.BytesIO(json.dumps({'embeddings': [[0.1] * 4 for _ in texts], 'id': 'stub'}).encode()),\n        }\n\n    with patch.object(model.client, 'invoke_model', side_effect=invoke_model):\n        for count in (96, 97):\n            requests.clear()\n            try:\n                result = await embedder.embed_documents([f'text {i}' for i in range(count)])\n            except Exception as exc:\n                print(f'{count} inputs -> {type(exc).__name__}, status={getattr(exc, \"status_code\", None)}, calls={len(requests)}, texts per call={[len(r[\"texts\"]) for r in requests]}')\n            else:\n                print(f'{count} inputs -> {len(result.embeddings)} embeddings, calls={len(requests)}, texts per call={[len(r[\"texts\"]) for r in requests]}')\n\nasyncio.run(main())\n# 96 inputs -> 96 embeddings, calls=1, texts per call=[96]\n# 97 inputs -> ModelRequestRejectedError, status=400, calls=1, texts per call=[97]","primaryOutput":null,"comparisonOutput":null}],"createdAt":1796072363645}]}