OpenAI-compatible chat completions API — just change the base URL and model name.
DeepInfra offers an OpenAI-compatible chat completions API for all LLM models at the best prices for open-source model inference. For other model types (embeddings, image generation, speech, reranking, and more), see More APIs. The endpoint is:
https://api.deepinfra.com/v1/openai
The only changes you need to make from your existing OpenAI code:
Set base_url to https://api.deepinfra.com/v1/openai
To create a longer conversation, include the full message history in every request. The model uses this context to provide better answers.
from openai import OpenAIopenai = OpenAI( api_key="$DEEPINFRA_TOKEN", base_url="https://api.deepinfra.com/v1/openai",)chat_completion = openai.chat.completions.create( model="deepseek-ai/DeepSeek-V3", messages=[ {"role": "system", "content": "Respond like a michelin starred chef."}, {"role": "user", "content": "Can you name at least two different techniques to cook lamb?"}, {"role": "assistant", "content": "Bonjour! Let me tell you, my friend, cooking lamb is an art form..."}, {"role": "user", "content": "Tell me more about the second method."}, ],)print(chat_completion.choices[0].message.content)
import OpenAI from "openai";const openai = new OpenAI({ baseURL: "https://api.deepinfra.com/v1/openai", apiKey: "$DEEPINFRA_TOKEN",});const completion = await openai.chat.completions.create({ messages: [ {role: "system", content: "Respond like a michelin starred chef."}, {role: "user", content: "Can you name at least two different techniques to cook lamb?"}, {role: "assistant", content: "Bonjour! Let me tell you, my friend, cooking lamb is an art form..."}, {role: "user", content: "Tell me more about the second method."} ], model: "deepseek-ai/DeepSeek-V3",});console.log(completion.choices[0].message.content);
curl "https://api.deepinfra.com/v1/openai/chat/completions" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $DEEPINFRA_TOKEN" \ -d '{ "model": "deepseek-ai/DeepSeek-V3", "messages": [ {"role": "system", "content": "Respond like a michelin starred chef."}, {"role": "user", "content": "Can you name at least two different techniques to cook lamb?"}, {"role": "assistant", "content": "Bonjour! Let me tell you..."}, {"role": "user", "content": "Tell me more about the second method."} ] }'
The longer the conversation, the more tokens it uses. The maximum conversation length is determined by the model’s context size.
Set service_tier to "priority" to request priority inference on supported models. Priority requests get faster time-to-first-token and higher throughput during peak demand.
Priority inference incurs a 50% surcharge on top of the model’s standard per-token price.
The response includes a service_tier field confirming which tier was actually used. Not all models support priority tiers — check the model page for availability. If a model doesn’t support priority inference, the request is served at the standard tier and billed at the standard price; no error is returned.
The maximum number of tokens that can be generated in a single response is model-dependent, with a hard cap of 16384 tokens for most models. Set max_tokens to control the limit for a specific request.
If you need a longer response, use response continuation: send a follow-up request with the previous response included as an assistant message, and the model will continue from where it left off.
curl "https://api.deepinfra.com/v1/openai/chat/completions" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $DEEPINFRA_TOKEN" \ -d '{ "model": "deepseek-ai/DeepSeek-V3", "messages": [ {"role": "user", "content": "Write a very long essay about AI."}, {"role": "assistant", "content": "<previous truncated response>"} ], "max_tokens": 4096 }'
Note: response continuation cannot extend past the model’s total context window. A 400 error is returned when the total context size is exceeded.