Grok 2

Grok-2, xAI's latest language model, boasts superior reasoning, coding, and chat capabilities, outperforming many popular LLMs.

~8.77s
~$0.003

API Format: OpenAI GPT (Standard Format)

This model uses OpenAI-compatible request/response format.

 1import requests
 2
 3url = "https://api.segmind.com/v1/grok-2"
 4
 5headers = {
 6    "Authorization": "Bearer YOUR_API_KEY",
 7    "Content-Type": "application/json"
 8}
 9
10data = {
11    "messages": [
12        {
13            "role": "user",
14            "content": [
15                {
16                    "type": "text",
17                    "text": "What's in this image?"
18                },
19                {
20                    "type": "image_url",
21                    "image_url": {
22                        "url": "https://example.com/image.jpg"
23                    }
24                }
25            ]
26        }
27    ]
28}
29
30response = requests.post(url, json=data, headers=headers)
31print(response.json())

API Endpoint

POST https://api.segmind.com/v1/grok-2

Parameters

messagesrequired
object[]

Array of message objects with role and content. Content can be text or multimodal (text + images).

Array items:
rolerequired
string

Role of the message sender

Allowed values :
"user""assistant"
contentrequired
array

String or array of content blocks

Response Format

{
  "id": "chat_abc123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "grok-2",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "I can see a beautiful sunset over the ocean with vibrant orange and pink hues in the sky."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 56,
    "completion_tokens": 31,
    "total_tokens": 87
  }
}

Image Input Format

Important: OpenAI GPT (Standard Format) Format

Images can be provided as URLs or base64 data URIs (data:image/jpeg;base64,...)

This model supports vision capabilities. You can include images in your requests.

Common Error Codes

The API returns standard HTTP status codes. Detailed error messages are provided in the response body.

400

Bad Request

Invalid message format or parameters

401

Unauthorized

Missing or invalid API key

403

Forbidden

Insufficient permissions

404

Not Found

Model or endpoint not found

406

Insufficient Credits

Not enough credits to process request

429

Rate Limited

Too many requests

500

Server Error

Internal server error

502

Bad Gateway

Service temporarily unavailable

504

Timeout

Request timed out