<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jochem Kleine on Medium]]></title>
        <description><![CDATA[Stories by Jochem Kleine on Medium]]></description>
        <link>https://medium.com/@jochemkleine?source=rss-5f482bd8423f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*02EEHg-TOrxDFGloP0X0mA.jpeg</url>
            <title>Stories by Jochem Kleine on Medium</title>
            <link>https://medium.com/@jochemkleine?source=rss-5f482bd8423f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 09:47:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jochemkleine/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Migrating from OpenAI (GPT 3.5 / 4o Mini) to Amazon Bedrock(Claude 3 Haiku) Part 1: the ‘Why’]]></title>
            <link>https://medium.com/@jochemkleine/migrating-from-openai-gpt-3-5-4o-mini-to-amazon-bedrock-claude-3-haiku-part-1-the-why-a2a782aabb2a?source=rss-5f482bd8423f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2a782aabb2a</guid>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[amazon-bedrock]]></category>
            <category><![CDATA[claude]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Jochem Kleine]]></dc:creator>
            <pubDate>Wed, 24 Jul 2024 06:56:08 GMT</pubDate>
            <atom:updated>2024-07-24T07:39:37.580Z</atom:updated>
            <content:encoded><![CDATA[<h3>Migrating from OpenAI (GPT 3.5 / 4o Mini) to Amazon Bedrock (Claude 3 Haiku) Part 1: the ‘Why’</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ko42gQrYSKTEyZ73431pdQ.png" /></figure><p>For the past few months, my mobile app ‘Shimmers’ (<a href="https://apps.apple.com/us/app/shimmers/id6464588154">iOS</a> / <a href="https://play.google.com/store/apps/details?id=com.shimmers.app">Android</a> link) has used the OpenAI GPT 3.5 API for its core game mechanic: generating text clues based on user-submitted questions and guesses. This worked decently well for a while, but in todays environment, standing still is falling behind. Recently, I’ve migrated my API calls to Claude 3 Haiku instead, through Amazon Bedrock. The process seems as easy as swapping out one API call for another, but as always, things turned out to be a little more involved than that. Not only on the technical side, but also the functional; making the decision to migrate or stick to the OpenAI implementation.</p><p>In this article I’ll elaborate on the decision making process (the ‘why’), and how I ended up favouring Amazon Bedrock &amp; Claude 3 Haiku over OpenAI’s GPT 4o mini.</p><p>In part 2, we’ll look at detailed implementation steps (the ‘how’) for migrating from OpenAI to Claude &amp; Amazon Bedrock.</p><p><strong>OpenAI’s GPT 4o mini &amp; Claude 3 Haiku on Amazon Bedrock: A Comparison</strong></p><p>For the GenAI app builder, there has never been a better time than today, with fierce competition among tech giants bringing better models on the daily. But it also brings challenges. What model should you use for your specific usecase? And, a few months down the line, are you still using the right one?</p><p>In this article and the next, we’ll talk through my recent migration of GPT 3.5 backed by OpenAI, to Claude 3 Haiku on AWS Bedrock. At the time of <em>migration</em>, GPT 3.5 was the main contender for a cheap and effective consumer-grade API by OpenAI. A comparison of GPT 3.5 and Claude 3 Haiku on Bedrock resulted in a very clear cut case for Claude 3 Haiku.</p><p>However, at the time of <em>writing</em>, OpenAI has just released <a href="https://openai.com/index/gpt-4o-mini-advancing-cost-efficient-intelligence/">GPT-4o mini</a>. This flips some of the considerations, like cost, on its head. Since GPT 3.5 is deprecated now, we’ll stick to the comparison of Claude Haiku and GPT 4o mini for the remainder of the article. Though the comparison is now much closer, I would still stick with my choice of Claude 3 Haiku and Amazon Bedrock over GPT 4o Mini for my specific use case.</p><p>There are a few important axes to consider when choosing between GPT 4o Mini on OpenAI, and Claude 3 Haiku on Bedrock.</p><ul><li>Cost</li><li>Quality &amp; Performance</li><li>Security &amp; Integration</li><li>Agility</li><li>Drawbacks</li></ul><p>We’ll go over the different considerations one by one.</p><ol><li><strong>Cost</strong></li></ol><p>For me, one of the key reasons to think about migrating in the first place was cost: GPT 3.5 at $0.00050 per 1k input tokens was twice as expensive as Claude 3 Haiku.</p><p>The release of GPT 4o mini makes things more interesting though: it’s <a href="https://openai.com/api/pricing/">pricing actually undercuts</a> Claude 3 Haiku (see pricing when called using <a href="https://aws.amazon.com/bedrock/pricing/">Amazon Bedrock</a>):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BUbE3leeI3HMoTPcGVp4WA.png" /><figcaption>Pricing as of 23rd of July, 2024.</figcaption></figure><p>Now, Claude 3 Haiku is the more expensive alternative, at about twice the price as GPT 4o mini. In the grand scheme of things, it’s still one of the cheaper options; Claude 3 Haiku is about 5 times less expensive than gpt 4o, and about 100 times less expensive than the GPT 4 API.</p><p>However, between 4o mini and Haiku, <strong>gpt 4o mini takes the cake</strong>. A significant change from GPT 3.5. So what about other axes?</p><p>2. <strong>Quality</strong> <strong>&amp; Performance</strong></p><p>When we look at <a href="https://www.vellum.ai/blog/gpt-4o-mini-v-s-claude-3-haiku-v-s-gpt-3-5-turbo-a-comparison">standard benchmarks for large language models</a>, GPT 4o mini again seems to beat Haiku on basically all benchmarks.</p><p>It’s a bit more nuanced than that, though.</p><p>Here’s an example of a comparison I ran for my specific usecase:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sME6oC58gjkqCIQI6vSLvQ.png" /><figcaption>Models boast different answering styles</figcaption></figure><p>All models are using the same temperature and ‘system message’; the instruction to act like a figure from history using a certain emotion, in this case Grumpy Abraham Lincoln.</p><p>GPT 3.5 doesn’t get much farther than the facts. 4o mini is quite similar, though some emotion is added to the answer.</p><p>The difference in tone between Claude and GPT though, is striking. Not to say that Claude 3 Haiku’s answer is objectively better, but its definitely different on many fronts. Claude has always been known to be much more ‘chatty’ than GPT. It also seems to be more lively in its answers. For some use cases, the aforementioned points would detract from its value. For my project though, this is closer to what I’m looking for for my usecase.</p><p>The key takeaway here is to always pay attention to benchmarks, but to further experiment with different models to find out which model fits your use case best. For me, that model was<strong> Claude 3 Haiku</strong>.</p><p>In terms of <strong>performance</strong>, gpt 4o mini also came out ahead in my experiments, though not in a groundbreaking way. For my use case, minor increases in performance did not weigh up against the perceived increase in quality.</p><p><strong>3. Security &amp; Integration</strong></p><p>The backend of the project I was running this migration for (Shimmers) was already entirely built on AWS. This was an important reason for me to consider integrating with Amazon Bedrock instead of the OpenAI API.</p><p>To call GPT 4o mini, you just need one thing: a valid API key. Should that key ever be compromised though (by accidentally committing it to a public repo, for example) all bets are off; a bad actor could completely drain any open OpenAI credits in minutes.</p><p>I was keen to get rid of this vulnerability and Amazon Bedrock allowed me to do so. Because I only needed to use LLM capabilities inside a few lambda functions, I could integrate with AWS IAM to provide only those specific IAM roles with the ability to call Claude 3 Haiku (through Bedrock). No need for long term credentials.</p><p>Another boon for Bedrock here is the fact that it offers nice <a href="https://aws.amazon.com/bedrock/guardrails/">post-processing capabilities</a> in the form of <strong>guardrails </strong>to, for example, block answers with harmful content. As a developer hosting an app on the App Store and Play Store, you’re expected to offer your users a safe environment. Because the nature of these LLMs is often unpredictable, I’ve already pre-emptively had to up the age rating of Shimmers to a higher level, just to be sure no minors see harmful content. Extra, easy to use guardrails are very important for my usecase.</p><p><strong>4. Agility</strong></p><p>When I was actively migrating towards Amazon Bedrock and Claude, away from OpenAI, the comparison was clear as day; GPT 3.5 was clearly inferior to Haiku on basically all fronts. With the recent introduction of gpt 4o mini, the comparison became much more nuanced.</p><p>With the space moving so quickly, it makes sense to be able to quickly swap between different models based on their quality, performance and cost. Migrating from OpenAI to Amazon Bedrock wasn’t hard, but there were a number of steps involved, as we’ll see in the follow-up post that will step through all the technical details.</p><p>The very fact that OpenAI can suddenly release a model (4o mini) that is competitively priced and of great quality, is a great example of why you want to be able to be agile; to boast the lowest possible switching cost.</p><p>AWS recently released the Amazon Bedrock <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference.html">Converse API</a> that plays into this really well. This API provides a single interface for calling LLMs from a number of vendors (e.g. Anthropic’s Claude, Llama, and more). I found the Converse API to be structured in a very similar way to OpenAI’s API too, so the translation was easy.</p><p>This gives us significantly more agility in the future, when one of the key players suddenly releases a new, cheaper model. +1 for Amazon Bedrock.</p><p><strong>5. Drawbacks</strong></p><p>So far, my verdict has leaned towards Amazon Bedrock &amp; Claude 3 Haiku, but there are some important drawbacks to consider.</p><p><strong>Usage limits</strong>: at <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/quotas.html">up to 1000 requests per minute for Claude 3 Haiku</a> (given you’re querying in the right region), Amazon Bedrock’s quota limit is quite restrictive. Shimmers luckily (?) isn’t there yet, but since this limit does not look to be alterable, you’ll have to implement backoff mechanisms or fix this problem another way should you exceed that limit. This, in my opinion, is currently the largest detractor from moving towards Amazon Bedrock.</p><p><strong>Regional availability: </strong>Many Bedrock powered models, Haiku included, are far from available in every AWS region. For my usecase, the closest region where Haiku is available is eu-east-1, and using Claude 3 Haiku there also means diminished usage limits (400 requests per minute instead of 1000). Having to do cross region calls might affect latency.</p><p><strong>No out of the box observability</strong>: OpenAI provides some straight forward graphs to keep track of the amount of requests per hour, the cost per day, etcetera. It’s possible to view this information in the AWS Billing Console, but there are no nice graphs out of the box; you’ll have to implement this yourself. I just implemented some custom Cloudwatch Metrics and a Cloudwatch Dashboard, but this does incur cost and extra work.</p><p><strong>Conclusion</strong></p><p>Looking to migrate from OpenAI to Amazon Bedrock, or trying to decide which option suits your greenfield use case best? You’ve got a tough decision ahead of you, because (you guessed it): it depends.</p><p>You’ll have to make a detailed comparison based on the aforementioned axes (and more — let me know which key considerations I might have missed). In my case, the decision to go with Amazon Bedrock &amp; Claude 3 Haiku might not be the obvious one given the higher per request costs and standard benchmark results. However, the increased agility, quality, security, and integration with other AWS resources flips the pendulum towards AWS Bedrock &amp; Claude 3 Haiku.</p><p><strong>Next Up</strong></p><p>In part 2 of the series we’ll go over the detailed technical steps required migrate over your OpenAI API implementation to Amazon Bedrock including</p><ul><li>Setting up Amazon Bedrock.</li><li>Using the Bedrock Converse API.</li><li>required AWS CDK changes (f.e. IAM permissions).</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2a782aabb2a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Abstract frontend, granular backend: integrating Flutter and Amplify Authenticator with AWS CDK]]></title>
            <link>https://medium.com/@jochemkleine/abstract-frontend-granular-backend-integrating-flutter-and-amplify-authenticator-with-aws-cdk-0248f9de52a7?source=rss-5f482bd8423f------2</link>
            <guid isPermaLink="false">https://medium.com/p/0248f9de52a7</guid>
            <category><![CDATA[amplify]]></category>
            <category><![CDATA[aws-cdk]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Jochem Kleine]]></dc:creator>
            <pubDate>Mon, 03 Jun 2024 10:55:53 GMT</pubDate>
            <atom:updated>2024-06-03T10:55:53.890Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Abstract frontend, granular backend: integrating Flutter and Amplify Authenticator with AWS CDK</strong></p><p>In the olden days, many years ago, I implemented my first OAuth2 integration in an app that has since been sunset called GroupFinder. Meta was still Facebook, the only pandemic we knew of was that one online game called “Pandemic II”, and the most important discussions concerned whether the colour of the dress was blue or golden (it was totally blue by the way).</p><p>Those were the days…</p><p>… but not so much for frontend social login integrations.</p><p>Integrating something simple like Facebook log-in with an Android native app was quirky at best and a massive pain at worst. I remember wrestling my way through that Facebook API and I was not ready to do it again this time around.</p><p>For <a href="https://apps.apple.com/us/app/shimmers/id6464588154">Shimmers</a>, I’d had my eye on <a href="https://ui.docs.amplify.aws/flutter/connected-components/authenticator">Amplify Authenticator</a> for a while, which supposedly provided ways to add complete authentication flows with minimal boilerplate. After running a quick PoC, I was impressed enough with the time it took to set up a workable solution. A side project was the perfect way to give implementing library into a real project a try!</p><p>The app infra so far had been written using AWS CDK. Amplify though, offers the <a href="https://docs.amplify.aws/gen1/flutter/tools/cli/start/key-workflows/">Amplify CLI</a> as a way to quickly set up components through simple commands like</p><pre>amplify init<br>amplify add auth      </pre><p>Using <a href="https://docs.amplify.aws/gen1/javascript/build-a-backend/auth/set-up-auth/">these commands</a> the steps for getting an authentication flow up and running basically entailed:</p><ul><li>Initialize an Amplify App.</li><li>Run amplify add auth and step through the menus to set up a basic Cognito User Pool &amp; Identity Pool.</li><li>Run amplify pull in your Flutter (or other frontend) project, which ends you up with the amplifyconfiguration.dart config file.</li><li>Set up some <a href="https://ui.docs.amplify.aws/flutter/connected-components/authenticator">boilerplate</a> Dart code for the frontend elements.</li><li><a href="https://docs.amplify.aws/gen1/flutter/build-a-backend/auth/add-social-provider/">Add your social login provider of choice</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QEW18mPBH-k3eRwxi_a-Ig.png" /><figcaption>Amplify Authenticator generated UI</figcaption></figure><p><strong>Integration with existing CDK resources</strong></p><p>That’s all. Nice! But integrating this with my existing CDK-deployed API caused a problem. The Amplify CLI has it’s own way of adding an API Gateway and compute integrations ( amplify add api ), but I wanted more granular control for this part of the application, and wasn’t ready to rewrite my previous API implementation (hey, side project time is sparse).</p><p>Thus, we need a way to integrate these two ways of deploying AWS resources such that</p><ol><li>we can use <em>only</em> the Authentication implementation that Amplify offers in isolation.</li><li>The rest of the backend application can still be defined in AWS CDK, and be deployed using CI/CD in my existing workflow (CodeCatalyst).</li></ol><p>The solution, in the end, takes some know-how of the different frameworks to set up, but is conceptually simple, as seen in the architecture diagram below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*TmL3bAFVVk54II_KMsx68g.png" /></figure><p>Setting up this architecture contains a few steps, of which the <strong>order</strong> is crucial</p><ol><li><strong>Setting up Cognito resources, including unauthenticated and authenticated IAM roles.</strong></li></ol><p>As seen in the previous section, this part uses the Amplify CLI, and is relatively straightforward at that. Importantly, we have to do this for every environment in which we want to add authentication.</p><p><strong>2. Authorizing the (un)authenticated IAM roles to call our API</strong></p><p>Once the IAM roles are automagically created using the Amplify CLI, we need to allow them to call the API Gateway. This presents us with a problem though: we want to import the IAM roles by their respective ARNs, but how do we know come to know these ARNs in our CDK application code? There are a few solutions, all of which are imperfect but workable:</p><ul><li>Save / hardcode the IAM role ARN as an environment value (e.g. in cdk.json )</li><li>Create an SSM parameter pointing at the IAM Role ARN, fetch the SSM value when required.</li><li>“Compute” the IAM role ARN, which does adhere to naming standards: amplify-&lt;app_name&gt;-&lt;environment_name&gt;-&lt;id&gt;-authRole</li></ul><p>Because this was a side project for me and speed was important, I chose to go with the first option for now. In terms of CDK code, that might look something like this (with some IAM permissions that you should definitely scope down for your usecase):</p><pre>    const api = new apigateway.RestApi(this, &#39;ApiGateway&#39;, {<br>      restApiName: &#39;SomeApi&#39;,<br>      defaultMethodOptions: {<br>        authorizationType: apigateway.AuthorizationType.IAM,<br>      }<br>    });<br><br><br>this.addCognitoApiGatewayInvokeRights(this, this.account, api.restApiId,)<br><br>  addCognitoApiGatewayInvokeRights(scope: Construct, accountId: string, apiGatewayId: string) {<br>    iam.Role.fromRoleArn(scope, &quot;yourAuthRoleId&quot;, this.node.tryGetContext(&#39;AuthRoleARN&#39;);).addToPrincipalPolicy(<br>      new iam.PolicyStatement({<br>        actions: [&#39;execute-api:Invoke&#39;],<br>        resources: [<br>          `arn:aws:execute-api:eu-west-1:${accountId}:${apiGatewayId}/*/*/*`,<br>        ],<br>      })<br>    );<br>  }</pre><p><strong>3. Tweaking </strong><strong>amplifyconfigurationin your Flutter project</strong></p><p>With the last two steps out of the way we have Cognito resources created in AWS, as well as an authenticated and unauthenticated roles that are allowed to call our API Gateway, but our app still has no way of knowing this API gateway exists. As specified earlier in this article, once you’ve done amplify pull in your frontend project, you should end up with a neatly autogeneratedamplifyconfiguration file containing all the required information your app needs to authenticate with Cognito. This is found under the auth attribute.</p><p>Were you to add an api using amplify add api , then this attribute would also be available in the spec, and would look something like this</p><pre>    &quot;api&quot;: {<br>        &quot;plugins&quot;: {<br>            &quot;awsAPIPlugin&quot;: {<br>                &quot;personApi&quot;: {<br>                    &quot;endpointType&quot;: &quot;REST&quot;,<br>                    &quot;endpoint&quot;: &quot;https://xyz.execute-api.eu-west-1.amazonaws.com/prod/&quot;,<br>                    &quot;region&quot;: &quot;eu-west-1&quot;,<br>                    &quot;authorizationType&quot;: &quot;AWS_IAM&quot;<br>                }<br>            }<br>        }<br>    },</pre><p>We can add this snippet to our existing amplifyconfiguration file to mimic this automatically created config, only this time we point at our own API gateway.</p><p>To do this, we edit theendpoint attribute to point at the actual API gateway URL.</p><p>An important consideration here is that we don’t want to be manually editing these configuration files all the time. In order to keep these configs tidy, you could create different versions (for different environments) and check them into version control.</p><p>And that’s it! Using this configuration, your app will authenticate with Cognito, and use the retrieved credentials to call our AWS CDK’ created API Gateway, which is set to only authorize IAM principals.</p><p><strong>Conclusion</strong></p><p>The Amplify frontend component suites, as well as the Authentication component offers some great benefits to quickly stand up an authentication flow. Through the aforementioned steps, we can use only these parts of Amplify, while sticking with a more granular implementation for the API implementation.</p><p>Its important to note that integrating these frameworks in this way does introduce a few weaknesses into the architecture (keeping track of different amplifyconfiguration files, manually running amplify CLI commands against your environments, referencing Amplify-created IAM role ARNs in our CDK app). Know of a better way to achieve this integration? Leave a comment below, I’m all ears.</p><p>Want to actually use the authentication flow you just read about? You can! Check out Shimmers on <a href="https://play.google.com/store/apps/details?id=com.shimmers.app">Android</a> or <a href="https://apps.apple.com/us/app/shimmers/id6464588154">iOS</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0248f9de52a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>