Skip to main content
POST
/
v1
/
chat
/
completions
Create chat completion
curl --request POST \
  --url https://api.dgrid.ai/v1/chat/completions \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "openai/gpt-4o",
  "messages": [
    {
      "role": "user",
      "content": "What is the meaning of life?"
    }
  ]
}
'
{
  "id": "<string>",
  "object": "<string>",
  "created": 123,
  "model": "<string>",
  "choices": [
    {
      "index": 123,
      "message": {
        "role": "<string>",
        "content": "<string>",
        "reasoning_content": "<string>",
        "tool_calls": [
          {}
        ]
      },
      "finish_reason": "<string>"
    }
  ],
  "usage": {
    "prompt_tokens": 123,
    "completion_tokens": 123,
    "total_tokens": 123,
    "prompt_tokens_details": {
      "cached_tokens": 123,
      "text_tokens": 123,
      "audio_tokens": 123,
      "image_tokens": 123
    },
    "completion_tokens_details": {
      "text_tokens": 123,
      "audio_tokens": 123,
      "reasoning_tokens": 123
    }
  },
  "system_fingerprint": "<string>"
}
This page uses the same chat/completions operation as Create chat completion, with the playground above pre-filled for the generic chat schema. The notes below describe how to use this endpoint to request Gemini-backed image generation from an OpenAI-compatible client.
Include an image-generation model in model (such as gemini-2.0-flash-preview-image-generation), set stream as needed, and supply your prompt through messages. Optionally include contents for additional Gemini-style multimodal context alongside messages.

Provider-specific notes

FieldTypeRequiredDescription
modelstringYesImage-generation model identifier, e.g. gemini-2.0-flash-preview-image-generation.
messages[].contentstringYesPrompt text describing the desired image.
contentsarrayNoOptional Gemini-style content array for additional multimodal context, not part of the standard OpenAI chat schema.
The contents field is a DGrid extension layered on top of the standard chat completions schema — it lets you pass Gemini-native parts (such as inlineData) alongside the OpenAI-style messages array when the target model supports it.

Example: requesting an image

{
  "model": "gemini-2.0-flash-preview-image-generation",
  "stream": false,
  "messages": [
    {
      "role": "user",
      "content": "Generate an image of a futuristic city skyline at sunset."
    }
  ]
}

Response fields

The response follows the standard chat completions shape. The generated image is embedded directly in the assistant message content:
choices
array
Returned choice entries.
usage
object
Token usage summary.

Example response

200
{
  "id": "chatcmpl-abc123",
  "model": "gemini-2.0-flash-preview-image-generation",
  "object": "chat.completion",
  "created": 1719859200,
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "![generated image](data:image/png;base64,<base64-encoded-image-bytes>)"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 0,
    "total_tokens": 12
  }
}

Authorizations

Authorization
string
header
required

Your DGrid API key. All endpoints use Authorization: Bearer <DGRID_API_KEY>.

Body

application/json
model
string
required

Target model ID in provider/model-name format.

Example:

"openai/gpt-4o"

messages
object[]
required

Conversation message list.

temperature
number
default:1

Sampling temperature.

top_p
number
default:1

Nucleus sampling value.

n
integer
default:1

Number of choices to generate.

stream
boolean
default:false

Enable SSE streaming.

max_tokens
integer

Maximum token count.

max_completion_tokens
integer

Max completion-only tokens.

presence_penalty
number
default:0

Presence penalty.

frequency_penalty
number
default:0

Frequency penalty.

logit_bias
object

Token bias configuration.

stop

Stop sequence string or array.

tools
object[]

Tool definitions.

tool_choice

Tool selection behavior. Defaults to auto.

response_format
object

Response schema or JSON mode config.

seed
integer

Deterministic seed.

user
string

End-user identifier.

Response

Chat completion result.

id
string

Completion identifier.

object
string

Always chat.completion.

created
integer

Creation timestamp.

model
string

Model that served the request.

choices
object[]

Returned choices.

usage
object

Token usage breakdown.

system_fingerprint
string