{"id":496,"date":"2026-05-21T00:00:00","date_gmt":"2026-05-21T00:00:00","guid":{"rendered":"https:\/\/wordpress.securinsight.ca\/index.php\/2026\/05\/21\/ai-gateway-call-any-ai-model-through-ai-gateways-new-rest-api-6\/"},"modified":"2026-05-21T00:00:00","modified_gmt":"2026-05-21T00:00:00","slug":"ai-gateway-call-any-ai-model-through-ai-gateways-new-rest-api-6","status":"publish","type":"post","link":"https:\/\/wordpress.securinsight.ca\/index.php\/2026\/05\/21\/ai-gateway-call-any-ai-model-through-ai-gateways-new-rest-api-6\/","title":{"rendered":"AI Gateway &#8211; Call any AI model through AI Gateway&#8217;s new REST API"},"content":{"rendered":"<p>AI Gateway now uses the AI REST API on <code>api.cloudflare.com<\/code>. You can call any model \u2014 whether from OpenAI, Anthropic, Google, or hosted on Workers AI \u2014 through one unified API, using the same endpoints and authentication regardless of provider. Four endpoints are available:<\/p>\n<ul>\n<li><code>POST \/ai\/run<\/code> \u2014 universal endpoint for all models and modalities<\/li>\n<li><code>POST \/ai\/v1\/chat\/completions<\/code> \u2014 OpenAI SDK compatible<\/li>\n<li><code>POST \/ai\/v1\/responses<\/code> \u2014 OpenAI Responses API compatible<\/li>\n<li><code>POST \/ai\/v1\/messages<\/code> \u2014 Anthropic SDK compatible<\/li>\n<\/ul>\n<div>\n<figure>\n<pre data-language=\"bash\"><code class=\"language-bash\"><div><div><span>curl<\/span><span> <\/span><span>-X<\/span><span> <\/span><span>POST<\/span><span> <\/span><span>\"https:\/\/api.cloudflare.com\/client\/v4\/accounts\/<\/span><span>$CLOUDFLARE_ACCOUNT_ID<\/span><span>\/ai\/v1\/chat\/completions\"<\/span><span> <\/span><span><\/span><\/div><\/div><div><div><span>  <\/span><span>--header<\/span><span> <\/span><span>\"Authorization: Bearer <\/span><span>$CLOUDFLARE_API_TOKEN<\/span><span>\"<\/span><span> <\/span><span><\/span><\/div><\/div><div><div><span>  <\/span><span>--header<\/span><span> <\/span><span>\"Content-Type: application\/json\"<\/span><span> <\/span><span><\/span><\/div><\/div><div><div><span>  <\/span><span>--data<\/span><span> <\/span><span>'{<\/span><\/div><\/div><div><div><span><span>    <\/span><\/span><span>\"model\": \"openai\/gpt-5.5\",<\/span><\/div><\/div><div><div><span><span>    <\/span><\/span><span>\"messages\": [{\"role\": \"user\", \"content\": \"What is Cloudflare?\"}]<\/span><\/div><\/div><div><div><span><span>  <\/span><\/span><span>}'<\/span><\/div><\/div><\/code><\/pre>\n<div>\n<div><\/div>\n<\/div>\n<\/figure>\n<\/div>\n<p>All AI Gateway features \u2014 logging, caching, rate limiting, and guardrails \u2014 are applied automatically. Third-party models are billed through <a href=\"https:\/\/developers.cloudflare.com\/ai-gateway\/features\/unified-billing\/\">Unified Billing<\/a>, so you do not need to manage separate provider API keys.<\/p>\n<p>Third-party model requests are routed through your account&#8217;s default gateway, which is created automatically on first use. To route requests through a specific gateway, add the <code>cf-aig-gateway-id<\/code> header.<\/p>\n<p>If you are already calling Workers AI models through the existing REST API, that path (<code>\/ai\/run\/@cf\/{model}<\/code>) continues to work. To call Workers AI models through AI Gateway, use the <code>@cf\/<\/code> model prefix (for example, <code>@cf\/moonshotai\/kimi-k2.6<\/code>) and include the <code>cf-aig-gateway-id<\/code> header to specify which gateway to route through.<\/p>\n<p>For more details and examples, refer to the <a href=\"https:\/\/developers.cloudflare.com\/ai-gateway\/usage\/rest-api\/\">REST API documentation<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>AI Gateway now uses the AI REST API on api.cloudflare.com. You can call any model \u2014 whether from OpenAI, Anthropic, Google, or hosted on Workers AI \u2014 through one unified API, using the same endpoints and authentication regardless of provider. Four endpoints are available: POST \/ai\/run \u2014 universal endpoint for all models and modalities POST [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-496","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/posts\/496","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/comments?post=496"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/posts\/496\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/media?parent=496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/categories?post=496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/tags?post=496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}