Skip to content

Commit 2222651

Browse files
lmilanfabianrbzkong-apiopstomek-labuk
committed
Feat(ai-gateway): xAI provider (#3558)
* Download Plugin Schemas and Metadata for 3.13 * Download Plugin Schemas and Metadata for 3.13 (#3544) Co-authored-by: tomek-labuk <207846229+tomek-labuk@users.noreply.github.com> * Add 3.13 gw version * Update streaming document * Revert "Update streaming document" This reverts commit 8303169. * Add xAI provider * Update ai-proxy.yaml * Update ai-proxy.yaml * Create xai.svg * xai image generation examples and how-to * Update tags.json * Update Dictionary.txt * Update Dictionary.txt * Update xai.md * min version * Update ai-providers.yaml * Update ai-providers.yaml * Update ai-providers.yaml * Update ai-providers.yaml * Update ai-providers.yaml --------- Co-authored-by: fabianrbz <715229+fabianrbz@users.noreply.github.com> Co-authored-by: kong-apiops <122612077+kong-apiops@users.noreply.github.com> Co-authored-by: tomek-labuk <207846229+tomek-labuk@users.noreply.github.com> Co-authored-by: tomek-labuk <tomasz.labuk@konghq.com>
1 parent 6b1934e commit 2222651

File tree

11 files changed

+366
-0
lines changed

11 files changed

+366
-0
lines changed

.github/styles/base/Dictionary.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ RequestResponse
695695
Rerank
696696
reranking
697697
resourceVersion
698+
response_format
698699
Resty
699700
Resty
700701
resty
@@ -959,6 +960,7 @@ workingDir
959960
workqueue
960961
workspace
961962
workspace's
963+
xai
962964
xbox
963965
xenial
964966
yaml

app/_data/plugins/ai-proxy.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,63 @@ providers:
428428
model_example: 'gpt-4o'
429429
min_version: '3.11'
430430

431+
- name: 'xAI'
432+
url_pattern: 'https://api.x.ai:443/{route_type_path}'
433+
min_version: '3.13'
434+
chat:
435+
supported: true
436+
streaming: false
437+
upstream_path: '/v1/chat/completions'
438+
route_type: 'llm/v1/chat'
439+
model_example: 'grok-4'
440+
min_version: '3.13'
441+
completions:
442+
supported: false
443+
streaming: false
444+
embeddings:
445+
supported: false
446+
streaming: false
447+
files:
448+
supported: false
449+
streaming: false
450+
batches:
451+
supported: false
452+
streaming: false
453+
assistants:
454+
supported: false
455+
streaming: false
456+
responses:
457+
supported: true
458+
streaming: false
459+
upstream_path: '/v1/responses'
460+
route_type: 'llm/v1/responses'
461+
model_example: 'gpt-4'
462+
min_version: '3.13'
463+
audio:
464+
speech:
465+
supported: false
466+
streaming: false
467+
transcriptions:
468+
supported: false
469+
streaming: false
470+
translations:
471+
supported: false
472+
streaming: false
473+
image:
474+
generations:
475+
supported: true
476+
streaming: false
477+
upstream_path: '/v1/images/generations'
478+
route_type: 'image/v1/images/generations'
479+
model_example: 'grok-2-image'
480+
min_version: '3.13'
481+
edits:
482+
supported: false
483+
streaming: false
484+
realtime:
485+
supported: false
486+
streaming: false
487+
431488
parameters:
432489
provider: 'config.targets[].model.provider'
433490
route_type: 'config.targets.route_type'

app/_data/schemas/frontmatter/tags.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@
194194
"webhook",
195195
"websocket",
196196
"windows",
197+
"xai",
197198
"zipkin",
198199
"zone-tokens",
199200
"zones"
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
title: Set up AI Proxy for image generation with Grok
3+
content_type: how_to
4+
related_resources:
5+
- text: AI Gateway
6+
url: /ai-gateway/
7+
- text: AI Proxy
8+
url: /plugins/ai-proxy/
9+
10+
description: Configure the AI Proxy plugin to create an image generation route using xAI Grok.
11+
12+
products:
13+
- gateway
14+
- ai-gateway
15+
16+
works_on:
17+
- on-prem
18+
- konnect
19+
20+
min_version:
21+
gateway: '3.13'
22+
23+
plugins:
24+
- ai-proxy
25+
26+
entities:
27+
- service
28+
- route
29+
- plugin
30+
31+
tags:
32+
- ai
33+
- xai
34+
35+
tldr:
36+
q: How do I use the AI Proxy plugin to generate images with xAI?
37+
a: Create a Gateway Service and a Route, then enable the AI Proxy plugin and configure it with the `image/v1/images/generations` route type, the xAI provider, the Grok model, and your xAI API key.
38+
39+
tools:
40+
- deck
41+
42+
prereqs:
43+
inline:
44+
- title: xAI
45+
include_content: prereqs/xai
46+
icon_url: /assets/icons/xai.svg
47+
entities:
48+
services:
49+
- example-service
50+
routes:
51+
- example-route
52+
53+
cleanup:
54+
inline:
55+
- title: Clean up Konnect environment
56+
include_content: cleanup/platform/konnect
57+
icon_url: /assets/icons/gateway.svg
58+
- title: Destroy the {{site.base_gateway}} container
59+
include_content: cleanup/products/gateway
60+
icon_url: /assets/icons/gateway.svg
61+
---
62+
63+
## Configure the plugin
64+
65+
Set up AI Proxy to use the `image/v1/images/generations` route type and the xAI [Grok 2 Image Gen](https://docs.x.ai/docs/models/grok-2-image) model:
66+
67+
{% entity_examples %}
68+
entities:
69+
plugins:
70+
- name: ai-proxy
71+
config:
72+
route_type: image/v1/images/generations
73+
genai_category: image/generation
74+
auth:
75+
header_name: Authorization
76+
header_value: Bearer ${xai_api_key}
77+
model:
78+
provider: xai
79+
name: grok-2-image
80+
variables:
81+
xai_api_key:
82+
value: $XAI_API_KEY
83+
{% endentity_examples %}
84+
85+
## Validate
86+
87+
Send a request containing a prompt and a response format to validate:
88+
89+
{% validation request-check %}
90+
url: /anything
91+
status_code: 201
92+
method: POST
93+
headers:
94+
- 'Accept: application/json'
95+
- 'Content-Type: application/json'
96+
body:
97+
prompt: Generate an image of King Kong
98+
response_format: url
99+
{% endvalidation %}

app/_includes/prereqs/xai.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
This tutorial uses xAI:
2+
1. [Create an xAI account](https://accounts.x.ai/account).
3+
1. In your [xAI console ](https://console.x.ai/), click **Create an API key**.
4+
1. In the **Name** field, enter a name for the key.
5+
1. Click **Create API key**.
6+
1. Create a decK variable with the API key:
7+
8+
```sh
9+
export DECK_XAI_API_KEY: 'YOUR XAI API KEY'
10+
```
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
title: 'Chat route with xAI'
3+
description: 'Configure a chat route using the xAI Grok 4 model.'
4+
5+
min_version:
6+
gateway: '3.13'
7+
8+
weight: 900
9+
10+
min_version:
11+
gateway: '3.13'
12+
13+
requirements:
14+
- xAI account
15+
16+
config:
17+
targets:
18+
- route_type: llm/v1/chat
19+
auth:
20+
header_name: Authorization
21+
header_value: Bearer ${key}
22+
model:
23+
provider: xai
24+
name: grok-4
25+
options:
26+
max_tokens: 512
27+
temperature: 1.0
28+
29+
variables:
30+
key:
31+
value: $XAI_API_KEY
32+
description: The API key to use to connect to xAI.
33+
34+
tools:
35+
- deck
36+
- admin-api
37+
- konnect-api
38+
- kic
39+
- terraform
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
title: 'Image generation with xAI'
3+
description: 'Configure an image generation route with the xAI Grok 2 Image Gen model.'
4+
5+
min_version:
6+
gateway: '3.13'
7+
8+
weight: 900
9+
10+
min_version:
11+
gateway: '3.13'
12+
13+
requirements:
14+
- xAI account
15+
16+
config:
17+
targets:
18+
- route_type: image/v1/images/generations
19+
genai_category: image/generation
20+
auth:
21+
header_name: Authorization
22+
header_value: Bearer ${{ env "DECK_XAI_API_KEY" }}
23+
model:
24+
provider: xai
25+
name: grok-2-image
26+
27+
variables:
28+
key:
29+
value: $XAI_API_KEY
30+
description: The API key to use to connect to xAI.
31+
32+
tools:
33+
- deck
34+
- admin-api
35+
- konnect-api
36+
- kic
37+
- terraform
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
title: 'Chat route with xAI'
3+
description: 'Configure a chat route using the xAI Grok 4 model.'
4+
5+
weight: 900
6+
7+
min_version:
8+
gateway: '3.13'
9+
10+
requirements:
11+
- xAI account
12+
13+
config:
14+
route_type: llm/v1/chat
15+
auth:
16+
header_name: Authorization
17+
header_value: Bearer ${key}
18+
model:
19+
provider: xai
20+
name: grok-4
21+
options:
22+
max_tokens: 512
23+
temperature: 1.0
24+
25+
variables:
26+
key:
27+
value: $XAI_API_KEY
28+
description: The API key to use to connect to xAI.
29+
30+
tools:
31+
- deck
32+
- admin-api
33+
- konnect-api
34+
- kic
35+
- terraform
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
title: 'Image generation with xAI'
3+
description: 'Configure an image generation route with the xAI Grok 2 Image Gen model.'
4+
5+
extended_description: |
6+
Configure an image generation route with the xAI Grok 2 Image Gen model.
7+
8+
See [Set up AI Proxy for image generation with Grok](/how-to/set-up-ai-proxy-for-image-generation-with-grok/) for a full how-to guide with this example.
9+
10+
min_version:
11+
gateway: '3.13'
12+
13+
weight: 900
14+
15+
min_version:
16+
gateway: '3.13'
17+
18+
requirements:
19+
- xAI account
20+
21+
config:
22+
route_type: image/v1/images/generations
23+
genai_category: image/generation
24+
auth:
25+
header_name: Authorization
26+
header_value: Bearer ${{ env "DECK_XAI_API_KEY" }}
27+
model:
28+
provider: xai
29+
name: grok-2-image
30+
31+
variables:
32+
key:
33+
value: $XAI_API_KEY
34+
description: The API key to use to connect to xAI.
35+
36+
tools:
37+
- deck
38+
- admin-api
39+
- konnect-api
40+
- kic
41+
- terraform

0 commit comments

Comments
 (0)