-
Notifications
You must be signed in to change notification settings - Fork 10.4k
[AIG ]Grok initial documentation #17764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ce43c47
Grok initial documentation
daisyfaithauma 9b2d1c6
Grok edit
daisyfaithauma c8ba35f
Update src/content/docs/ai-gateway/providers/grok.mdx
daisyfaithauma afe3c37
Update src/content/docs/ai-gateway/providers/grok.mdx
daisyfaithauma b517dff
Update src/content/docs/ai-gateway/providers/grok.mdx
daisyfaithauma eff6026
Update src/content/docs/ai-gateway/providers/grok.mdx
daisyfaithauma 9ba80d2
URL edits
daisyfaithauma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| --- | ||
| title: Grok | ||
| pcx_content_type: get-started | ||
| sidebar: | ||
| badge: | ||
| text: Beta | ||
| --- | ||
|
|
||
| [Grok](https://docs.x.ai/docs#getting-started) is s a general purpose model that can be used for a variety of tasks, including generating and understanding text, code, and function calling. | ||
|
|
||
| ## Endpoint | ||
|
|
||
| `https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/grok` | ||
|
|
||
| ## URL structure | ||
|
|
||
| When making requests to [Grok](https://docs.x.ai/docs#getting-started), replace `https://api.x.ai/v1` in the URL you are currently using with `https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/grok`. | ||
|
|
||
| ## Examples | ||
|
|
||
| ### cURL | ||
|
|
||
| ```bash title="Request" | ||
| curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/grok/v1/chat/completions \ | ||
| --header 'content-type: application/json' \ | ||
| --header 'Authorization: Bearer {grok_api_token}' \ | ||
| --data '{ | ||
| "model": "grok-beta", | ||
| "messages": [ | ||
| { | ||
| "role": "user", | ||
| "content": "What is Cloudflare?" | ||
| } | ||
| ] | ||
| }' | ||
daisyfaithauma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| If you are using the OpenAI SDK with JavaScript, you can set your endpoint like this: | ||
|
|
||
| ```js title="JavaScript" | ||
| import OpenAI from "openai"; | ||
|
|
||
| const openai = new OpenAI({ | ||
| apiKey: "<api key>", | ||
daisyfaithauma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| baseURL: "https://api.x.ai/v1", | ||
daisyfaithauma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| const completion = await openai.chat.completions.create({ | ||
| model: "grok-beta", | ||
| messages: [ | ||
| { | ||
| role: "system", | ||
| content: | ||
| "You are Grok, a chatbot inspired by the Hitchhiker's Guide to the Galaxy.", | ||
| }, | ||
| { | ||
| role: "user", | ||
| content: "What is the meaning of life, the universe, and everything?", | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| console.log(completion.choices[0].message); | ||
| ``` | ||
|
|
||
| If you are using the OpenAI SDK with Python, you can set your endpoint like this: | ||
|
|
||
| ```python title="Python" | ||
| import os | ||
| from openai import OpenAI | ||
|
|
||
| XAI_API_KEY = os.getenv("XAI_API_KEY") | ||
| client = OpenAI( | ||
| api_key=XAI_API_KEY, | ||
| base_url="https://api.x.ai/v1", | ||
daisyfaithauma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| completion = client.chat.completions.create( | ||
| model="grok-beta", | ||
| messages=[ | ||
| {"role": "system", "content": "You are Grok, a chatbot inspired by the Hitchhiker's Guide to the Galaxy."}, | ||
| {"role": "user", "content": "What is the meaning of life, the universe, and everything?"}, | ||
| ], | ||
| ) | ||
|
|
||
| print(completion.choices[0].message) | ||
| ``` | ||
|
|
||
| If you are using the Anthropic SDK with JavaScript, you can set your endpoint like this: | ||
|
|
||
| ```js title="JavaScript" | ||
| import Anthropic from "@anthropic-ai/sdk"; | ||
|
|
||
| const anthropic = new Anthropic({ | ||
| apiKey: "<api key>", | ||
daisyfaithauma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| baseURL: "https://api.x.ai/", | ||
daisyfaithauma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| const msg = await anthropic.messages.create({ | ||
| model: "grok-beta", | ||
| max_tokens: 128, | ||
| system: | ||
| "You are Grok, a chatbot inspired by the Hitchhiker's Guide to the Galaxy.", | ||
| messages: [ | ||
| { | ||
| role: "user", | ||
| content: "What is the meaning of life, the universe, and everything?", | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| console.log(msg); | ||
| ``` | ||
|
|
||
| If you are using the Anthropic SDK with Python, you can set your endpoint like this: | ||
|
|
||
| ```python title="Python" | ||
| import os | ||
| from anthropic import Anthropic | ||
|
|
||
| XAI_API_KEY = os.getenv("XAI_API_KEY") | ||
| client = Anthropic( | ||
| api_key=XAI_API_KEY, | ||
| base_url="https://api.x.ai", | ||
daisyfaithauma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| message = client.messages.create( | ||
| model="grok-beta", | ||
| max_tokens=128, | ||
| system="You are Grok, a chatbot inspired by the Hitchhiker's Guide to the Galaxy.", | ||
| messages=[ | ||
| { | ||
| "role": "user", | ||
| "content": "What is the meaning of life, the universe, and everything?", | ||
| }, | ||
| ], | ||
| ) | ||
|
|
||
| print(message.content) | ||
| ``` | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.