Skip to main content

Chat

Chat completions

POST /v1/chat/completions, /v1/completions, and /v1/responses in the OpenAI-compatible shape.

posthttps://api.pre.dev/v1/chat/completionsTry it

POST https://api.pre.dev/v1/chat/completions takes the OpenAI-compatible chat completion request body and returns the chat completion response. POST /v1/completions (text completions) and POST /v1/responses (Responses API shape) work the same way with their own bodies.

curl --fail-with-body -i https://api.pre.dev/v1/chat/completions \
  -H "Authorization: Bearer $PREDEV_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek/deepseek-v4.1-flash-1017",
    "messages": [
      { "role": "system", "content": "Answer in one sentence." },
      { "role": "user", "content": "Why is the sky blue?" }
    ]
  }'
import OpenAI from 'openai';

const client = new OpenAI({ baseURL: 'https://api.pre.dev/v1', apiKey: process.env.PREDEV_API_KEY! });

const { data: completion, response } = await client.chat.completions
  .create({
    model: 'deepseek/deepseek-v4.1-flash-1017',
    messages: [
      { role: 'system', content: 'Answer in one sentence.' },
      { role: 'user', content: 'Why is the sky blue?' },
    ],
  })
  .withResponse();
console.log(completion.choices[0].message.content);
console.log('credits:', response.headers.get('x-predev-credits-charged'));
import os
from openai import OpenAI

client = OpenAI(base_url="https://api.pre.dev/v1", api_key=os.environ["PREDEV_API_KEY"])

raw = client.chat.completions.with_raw_response.create(
    model="deepseek/deepseek-v4.1-flash-1017",
    messages=[
        {"role": "system", "content": "Answer in one sentence."},
        {"role": "user", "content": "Why is the sky blue?"},
    ],
)
completion = raw.parse()
print(completion.choices[0].message.content)
print("credits:", raw.headers.get("x-predev-credits-charged"))

Request

FieldNotes
modelThe model id exactly as listed by GET /v1/models; append :online for web search
messagesOpenAI chat messages, including image and file content parts
models, route, transformsFallbacks and advanced options
reasoning, reasoning_effortReasoning controls
plugins, web_search_optionsPlugins and web search
response_format, structured_outputs, tools, tool_choice, parallel_tool_callsTools and structured output
prediction, verbosity, session_idPredicted outputs, verbosity, session grouping
streamStreaming; the final chunk carries usage
userEnd-user identifier; pre.dev prefixes it with an identifier for your workspace

Every other standard field (temperature, max_tokens, stop, and so on) works as in the OpenAI API.

Response

The body is the standard chat completion response. id is the pre.dev generation id (pdg-…), model is the model that answered, and usage has the token counts.

{
  "id": "pdg-7c1e4b52-9a3d-4f8e-b0c6-2d5a8e913f47",
  "object": "chat.completion",
  "model": "deepseek/deepseek-v4.1-flash-1017",
  "choices": [
    {
      "index": 0,
      "message": { "role": "assistant", "content": "Sunlight scatters off air molecules, and blue light scatters most." },
      "finish_reason": "stop"
    }
  ],
  "usage": { "prompt_tokens": 21, "completion_tokens": 14, "total_tokens": 35 }
}
HeaderMeaning
x-predev-request-idpdr_…, the gateway’s id for this call
x-predev-credits-chargedCredits charged. Not sent on streamed responses; read GET /v1/generation afterwards
x-predev-credits-remainingBalance after the call; omitted when the workspace has no credit limit

Send x-predev-project-id: <projectId> to attribute the call to a project. See usage.

Errors

Errors use the OpenAI error shape. Account and billing errors (401, 402, 429, 503) add a predev object; errors from the model, such as an unknown model id, keep their HTTP status. See errors.

curl --fail-with-body https://api.pre.dev/v1/chat/completions \  -H "Authorization: Bearer $PREDEV_API_KEY" \  -H "Content-Type: application/json" \  -d '{"model":"deepseek/deepseek-v4.1-flash-1017","max_tokens":100,"stream":false,"reasoning":{"enabled":false},"messages":[{"role":"user","content":"Say hello in five words."}]}'
import osfrom openai import OpenAIclient = OpenAI(base_url="https://api.pre.dev/v1", api_key=os.environ["PREDEV_API_KEY"])completion = client.chat.completions.create(    model="deepseek/deepseek-v4.1-flash-1017",    max_tokens=100,    extra_body={"reasoning": {"enabled": False}},    messages=[{"role": "user", "content": "Say hello in five words."}],)print(completion.choices[0].message.content)
import OpenAI from 'openai';const client = new OpenAI({ baseURL: 'https://api.pre.dev/v1', apiKey: process.env.PREDEV_API_KEY });const completion = await client.chat.completions.create({  model: 'deepseek/deepseek-v4.1-flash-1017',  max_tokens: 100,  reasoning: { enabled: false },  messages: [{ role: 'user', content: 'Say hello in five words.' }],});console.log(completion.choices[0].message.content);
package mainimport (  "fmt"  "net/http"  "io/ioutil"  "strings")func main() {  url := "https://api.pre.dev/v1/chat/completions"  body := strings.NewReader(`{    "model": "deepseek/deepseek-v4.1-flash-1017",    "max_tokens": 100,    "stream": false,    "reasoning": {      "enabled": false    },    "messages": [      {        "role": "user",        "content": "Say hello in five words."      }    ]  }`)  req, _ := http.NewRequest("POST", url, body)  req.Header.Add("Content-Type", "application/json")  res, _ := http.DefaultClient.Do(req)  defer res.Body.Close()  body, _ := ioutil.ReadAll(res.Body)  fmt.Println(res)  fmt.Println(string(body))}
import java.net.URI;import java.net.http.HttpClient;import java.net.http.HttpRequest;import java.net.http.HttpResponse;import java.net.http.HttpResponse.BodyHandlers;import java.time.Duration;import java.net.http.HttpRequest.BodyPublishers;var body = BodyPublishers.ofString("""{  "model": "deepseek/deepseek-v4.1-flash-1017",  "max_tokens": 100,  "stream": false,  "reasoning": {    "enabled": false  },  "messages": [    {      "role": "user",      "content": "Say hello in five words."    }  ]}""");HttpClient client = HttpClient.newBuilder()  .connectTimeout(Duration.ofSeconds(10))  .build();HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()  .uri(URI.create("https://api.pre.dev/v1/chat/completions"))  .header("Content-Type", "application/json")  .POST(body)  .build();try {  HttpResponse<String> response = client.send(requestBuilder.build(), BodyHandlers.ofString());  System.out.println("Status code: " + response.statusCode());  System.out.println("Response body: " + response.body());} catch (Exception e) {  e.printStackTrace();}
using System;using System.Net.Http;using System.Text;var body = new StringContent("""{  "model": "deepseek/deepseek-v4.1-flash-1017",  "max_tokens": 100,  "stream": false,  "reasoning": {    "enabled": false  },  "messages": [    {      "role": "user",      "content": "Say hello in five words."    }  ]}""", Encoding.UTF8, "application/json");var client = new HttpClient();var response = await client.PostAsync("https://api.pre.dev/v1/chat/completions", body);var responseBody = await response.Content.ReadAsStringAsync();
use reqwest::{Result, Client};async fn main() -> Result<()> {  let client = Client::new();  let url = "https://api.pre.dev/v1/chat/completions";  let body = r#"{    "model": "deepseek/deepseek-v4.1-flash-1017",    "max_tokens": 100,    "stream": false,    "reasoning": {      "enabled": false    },    "messages": [      {        "role": "user",        "content": "Say hello in five words."      }    ]  }"#;  let res = client    .post(url)    .header("Content-Type", "application/json")    .body(body)    .send()    .await?    .text()    .await?;  println!("{}", res);  Ok(())}
{  "id": "pdg-043293a6-d1a8-4695-81fe-603ad4661ebb",  "object": "chat.completion",  "created": 1790500000,  "model": "deepseek/deepseek-v4.1-flash-1017",  "choices": [    {      "index": 0,      "message": {        "role": "assistant",        "content": "Hello there, nice to meet you."      },      "finish_reason": "stop"    }  ],  "usage": {    "prompt_tokens": 12,    "completion_tokens": 8,    "total_tokens": 20  },  "system_fingerprint": null}
POST
/v1/chat/completions

Authorization

AuthorizationBearer <token>

The workspace API key (pdk_…) from Integrations → Built-in in the pre.dev dashboard.

In: header

Header Parameters

x-predev-project-id?string

Attribute this call to one of the workspace's projects. An id the workspace does not own is ignored.

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

Response Body

The completion. With stream: true, server-sent chunks in the OpenAI format ending with data: [DONE].

TypeScript Definitions

Use the response body type in TypeScript.

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

Was this page helpful?