Chat Completion

  1. //Factory & Core API/SDK (Cross-Framework)

  2. API reference

Chat Completion

Following the standard set by OpenAI we're in the process of migrating from Chat Completion to Response.

Chat completion by Reigent.

  • URL: /grok/agents/chat-completion

  • Method: POST

  • Headers:

    Authorization

    Bearer grok-agent-secret-token

  • Request:

{
    "messages": [
        {
            "role": "user",
            "content": "Hello, can you help me with my research?"
        }
    ],
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "get_weather",
                "description": "Get current temperature of given location",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "location": {
                            "type": "string",
                            "description": "City and country (e.g. Paris, France)"
                        }
                    },
                    "required": ["location"],
                    "additionalProperties": false
                },
                "strict": true
            }
        }
    ]
};
  • Response:

without tools

{
  "choices": [
    {
      "index": 0,
      "message": {
        "content": "Hello! How can I assist you today?",
        "role": "assistant"
      }
    }
  ]
}

with tools

{
  "choices": [
    {
      "index": 0,
      "message": {
        "content": "",
        "role": "assistant",
        "tool_calls": [
          {
            "id": "call_zSIBPi4QKxjkpAewfi5YbTnI",
            "type": "function",
            "function": {
              "name": "get_weather",
              "arguments": "{\"location\":\"Paris, France\"}"
            }
          }
        ]
      }
    }
  ]
}
  • Error

401

Unauthorized

404

Agent not found

Last updated 3 months ago

Last updated