### Install OpenAI Client Library for Python Source: https://dev.synthetic.new/docs/api/getting-started Installs the official OpenAI Python client library, which is compatible with the Synthetic API. This is the first step to programmatically interact with the API. ```bash pip install openai ``` -------------------------------- ### Install and Run OpenCode (Bash) Source: https://dev.synthetic.new/docs/guides/opencode This snippet demonstrates the basic command to open OpenCode in your terminal. Ensure OpenCode is installed following its official guide before executing this command. ```bash opencode ``` -------------------------------- ### Start Octofriend Source: https://dev.synthetic.new/docs/guides/octofriend Starts the Octofriend AI coding assistant after installation. This is the command to run to begin using its features. ```bash octofriend ``` -------------------------------- ### List Available Models in Python Source: https://dev.synthetic.new/docs/api/getting-started Demonstrates how to list available models using the Synthetic client. This call retrieves a list of model IDs that can be used for API requests. ```python models = client.models.list() for model in models.data: print(model.id) ``` -------------------------------- ### Handle API Errors in Python Source: https://dev.synthetic.new/docs/api/getting-started Provides an example of how to handle potential API errors, such as general API errors or rate limit errors, when making requests to the Synthetic API. It uses try-except blocks to catch specific exceptions. ```python try: completion = client.chat.completions.create( model="hf:zai-org/GLM-4.6", messages=[{"role": "user", "content": "Hello!"}] ) except openai.APIError as e: print(f"API error: {e}") except openai.RateLimitError as e: print(f"Rate limit exceeded: {e}") ``` -------------------------------- ### Make Chat Completion API Call in Python Source: https://dev.synthetic.new/docs/api/getting-started Demonstrates how to make a chat completion API call using the configured Synthetic client. It specifies a model and provides a system message and a user message to get a response. ```python completion = client.chat.completions.create( model="hf:zai-org/GLM-4.6", messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Explain quantum computing in simple terms."} ] ) print(completion.choices[0].message.content) ``` -------------------------------- ### Install Claude Code CLI Source: https://dev.synthetic.new/docs/guides/claude-code Installs the Claude Code command-line interface globally using npm. This is the first step to using Claude Code with Synthetic. ```bash npm install -g @anthropic-ai/claude-code ``` -------------------------------- ### Example Chat Completion Request in Python Source: https://dev.synthetic.new/docs/openai/chat-completions A Python code example demonstrating how to use the Synthetic API for chat completions. It shows how to initialize the OpenAI client with API key and base URL, and how to make a 'create' call with model, messages, and other parameters. ```Python import openai client = openai.OpenAI( api_key="SYNTHETIC_API_KEY", base_url="https://api.synthetic.new/openai/v1" ) completion = client.chat.completions.create( model="hf:deepseek-ai\/DeepSeek-V3-0324", messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is the capital of France?"} ], max_tokens=100, temperature=0.7 ) print(completion.choices[0].message.content) ``` -------------------------------- ### Get Quotas - Example JSON Response Source: https://dev.synthetic.new/docs/synthetic/quotas An example JSON response from the Synthetic API's /quotas endpoint. It details the subscription limit, current requests, and the renewal date for the API usage. ```json { "subscription": { "limit": 135, "requests": 0, "renewsAt": "2025-09-21T14:36:14.288Z" } } ``` -------------------------------- ### Configure Synthetic API Client in Python Source: https://dev.synthetic.new/docs/api/getting-started Configures the OpenAI Python client to use Synthetic's API endpoint and your API key. It sets the `base_url` to Synthetic's API and retrieves the API key from environment variables. ```python import os import openai client = openai.OpenAI( api_key=os.environ.get("SYNTHETIC_API_KEY"), base_url="https://api.glhf.chat/v1/", ) ``` -------------------------------- ### Install Octofriend using npm Source: https://dev.synthetic.new/docs/guides/octofriend Installs the Octofriend coding assistant globally using npm. This command ensures the tool is available system-wide for immediate use. ```bash npm install --global --omit=dev octofriend ``` -------------------------------- ### Run Moltbot Terminal Command Source: https://dev.synthetic.new/docs/guides/moltbot This command initiates the Moltbot application in your terminal, allowing you to begin the setup process for integrating with providers like Synthetic. ```bash moltbot ``` -------------------------------- ### Example Response JSON Source: https://dev.synthetic.new/docs/openai/completions A sample JSON response for a successful text completion request. It includes details like the completion ID, model used, creation timestamp, and the generated text. ```json { "id": "49fb0537-dafc-441c-ad42-b4c4aa2f5193", "object": "text_completion", "created": 1757645512, "model": "accounts/fireworks/models/deepseek-v3-0324", "choices": [ { "index": 0, "text": " undeniably bright and holds the potential to revolutionize every aspect of our lives. As we stand on the cusp of technological advancements, AI is poised to become more sophisticated, integrated, and ethical. From transforming industries to enhancing daily conveniences, AI'", "logprobs": null, "finish_reason": "length" } ], "usage": { "prompt_tokens": 7, "total_tokens": 57, "completion_tokens": 50 } } ``` -------------------------------- ### Example Response - JSON Source: https://dev.synthetic.new/docs/openai/models This is an example JSON response from the Synthetic API's /models endpoint, showing a list of available models with their IDs and object type. ```json { "data": [ { "id": "hf:deepseek-ai/DeepSeek-V3.1", "object": "model" }, { "id": "hf:Qwen/Qwen3-235B-A22B-Instruct-2507", "object": "model" }, { "id": "hf:zai-org/GLM-4.6", "object": "model" }, { "id": "hf:openai/gpt-oss-120b", "object": "model" }, { "id": "hf:moonshotai/Kimi-K2-Instruct-0905", "object": "model" } ] } ``` -------------------------------- ### Get Quotas - Python Request Source: https://dev.synthetic.new/docs/synthetic/quotas Example Python code to make a GET request to the /quotas endpoint of the Synthetic API. It requires the 'requests' library and an API key for authorization. The response is printed as JSON. ```python import requests headers = { "Authorization": "Bearer SYNTHETIC_API_KEY" } response = requests.get( "https://api.synthetic.new/v2/quotas", headers=headers ) print(response.json()) ``` -------------------------------- ### Stream Chat Completion Responses in Python Source: https://dev.synthetic.new/docs/api/getting-started Shows how to handle streaming responses for chat completions, which is useful for long responses to improve user experience. It iterates over the streamed chunks and prints the content as it arrives. ```python completion = client.chat.completions.create( model="hf:zai-org/GLM-4.6", messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Write a detailed explanation of machine learning."} ], stream=True ) for chunk in completion: if chunk.choices[0].delta.content is not None: print(chunk.choices[0].delta.content, end='', flush=True) ``` -------------------------------- ### Streaming Response Example Source: https://dev.synthetic.new/docs/openai/completions An example of the Server-Sent Events (SSE) format for streaming responses from the completions endpoint. Each 'data:' line contains a JSON object representing a chunk of the completion. ```text data: {"id":"cmpl-abc123","object":"text_completion","created":1757644754,"model":"accounts/fireworks/models/deepseek-v3-0324","choices":[{"text":" in","index":0,"finish_reason":null}]} data: {"id":"cmpl-abc123","object":"text_completion","created":1757644754,"model":"accounts/fireworks/models/deepseek-v3-0324","choices":[{"text":" a","index":0,"finish_reason":null}]} data: {"id":"cmpl-abc123","object":"text_completion","created":1757644754,"model":"accounts/fireworks/models/deepseek-v3-0324","choices":[{"text":" far","index":0,"finish_reason":"length"}],"usage":{"prompt_tokens":5,"total_tokens":55,"completion_tokens":50}]} data: [DONE] ``` -------------------------------- ### Get Quotas - TypeScript Request Source: https://dev.synthetic.new/docs/synthetic/quotas Example TypeScript code to fetch API quota information using the 'fetch' API. This snippet demonstrates how to set the Authorization header with your API key and process the JSON response. ```typescript async function getQuotas() { const apiKey = "SYNTHETIC_API_KEY"; const response = await fetch("https://api.synthetic.new/v2/quotas", { headers: { "Authorization": `Bearer ${apiKey}` } }); const data = await response.json(); console.log(data); } getQuotas(); ``` -------------------------------- ### Send and Receive Messages (TypeScript) Source: https://dev.synthetic.new/docs/anthropic/messages Illustrates sending and receiving messages using the Anthropic API through Synthetic with TypeScript. This example requires the 'ai' SDK and an API key. It sends a user query and logs the assistant's text response. ```TypeScript import Anthropic from "@anthropic-ai/sdk"; const client = new Anthropic({ apiKey: "SYNTHETIC_API_KEY", baseURL: "https://api.synthetic.new/anthropic/v1", }); async function main() { const msg = await client.messages.create({ model: "hf:deepseek-ai/DeepSeek-V3-0324", maxTokens: 100, messages: [ { role: "user", content: "What is the capital of France?", }, ], }); console.log(msg.content[0].text); } main(); ``` -------------------------------- ### Send and Receive Messages (curl) Source: https://dev.synthetic.new/docs/anthropic/messages Provides a command-line example using curl to interact with the Synthetic API for sending and receiving messages. This method requires constructing the JSON payload and setting the appropriate headers, including the API key. ```bash curl -X POST https://api.synthetic.new/anthropic/v1/messages \ -H "x-api-key: SYNTHETIC_API_KEY" \ -H "content-type: application/json" \ -d '{ "model": "hf:deepseek-ai/DeepSeek-V3-0324", "max_tokens": 100, "messages": [ {"role": "user", "content": "What is the capital of France?"} ] }' ``` -------------------------------- ### Get Quotas - cURL Request Source: https://dev.synthetic.new/docs/synthetic/quotas Example cURL command to retrieve API quota information. This command sends a GET request to the /quotas endpoint, including the necessary Authorization header with your API key. ```bash curl -X GET https://api.synthetic.new/v2/quotas \ -H "Authorization: Bearer SYNTHETIC_API_KEY" ``` -------------------------------- ### Example JSON Response Source: https://dev.synthetic.new/docs/anthropic/messages This snippet demonstrates the structure of an example JSON response. It includes fields like id, type, role, content, model, stop_reason, stop_sequence, and usage statistics. This format is typical for message-based APIs. ```json { "id": "msg_abc123", "type": "message", "role": "assistant", "content": [ { "type": "text", "text": "The capital of France is Paris." } ], "model": "hf:deepseek-ai/DeepSeek-V3-0324", "stop_reason": "end_turn", "stop_sequence": null, "usage": { "input_tokens": 12, "output_tokens": 8 } } ``` -------------------------------- ### Count Tokens API Request - Python Source: https://dev.synthetic.new/docs/anthropic/messages/count-tokens Python example demonstrating how to use the Synthetic API's /messages/count_tokens endpoint to count input tokens for a given set of messages. It requires the 'anthropic' library and your API key. ```python import anthropic client = anthropic.Anthropic( api_key="SYNTHETIC_API_KEY", base_url="https://api.synthetic.new/anthropic/v1" ) # Count tokens for a simple text message response = client.messages.count_tokens( model="hf:deepseek-ai/DeepSeek-V3-0324", messages=[ {"role": "user", "content": "What is the capital of France?"} ] ) print(f"Input tokens: {response.input_tokens}") ``` -------------------------------- ### GET /openai/v1/models Source: https://dev.synthetic.new/docs/openai/models Lists and retrieves information about available models. This endpoint does not count against your subscription limits and shows all always-on models, plus recently used on-demand models. ```APIDOC ## GET /openai/v1/models ### Description Lists and retrieves information about available models. This endpoint does not count against your subscription limits and shows all always-on models, plus recently used on-demand models. ### Method GET ### Endpoint https://api.synthetic.new/openai/v1/models ### Parameters #### Query Parameters None #### Request Body None ### Request Example ```python import openai client = openai.OpenAI( api_key="SYNTHETIC_API_KEY", base_url="https://api.synthetic.new/openai/v1" ) # List all available models models = client.models.list() print(models) ``` ### Response #### Success Response (200) - **data** (array) - A list of model objects. - **id** (string) - The unique identifier for the model. - **object** (string) - The type of object, typically "model". #### Response Example ```json { "data": [ { "id": "hf:deepseek-ai/DeepSeek-V3.1", "object": "model" }, { "id": "hf:Qwen/Qwen3-235B-A22B-Instruct-2507", "object": "model" }, { "id": "hf:zai-org/GLM-4.6", "object": "model" }, { "id": "hf:openai/gpt-oss-120b", "object": "model" }, { "id": "hf:moonshotai/Kimi-K2-Instruct-0905", "object": "model" } ] } ``` ### Model Naming Convention All model IDs follow the pattern: `hf:{owner}/{model-name}` - **hf:** - Required prefix indicating a Hugging Face model - **owner** - The organization or user who published the model - **model-name** - The specific model name and version ``` -------------------------------- ### Streaming API Responses Source: https://dev.synthetic.new/docs/anthropic/messages This section illustrates how to handle streaming API responses. When `stream: true` is enabled, the API returns Server-Sent Events. The provided code examples show how to process these events in Python and TypeScript, along with a curl command for testing. ```python stream = client.messages.create( model="hf:deepseek-ai/DeepSeek-V3-0324", max_tokens=100, system="You are a helpful assistant.", messages=[{"role": "user", "content": "Hello!"}], stream=True ) for event in stream: if event.type == "content_block_delta": print(event.delta.text, end="") ``` ```typescript const stream = client.messages.create({ model: "hf:deepseek-ai/DeepSeek-V3-0324", max_tokens: 100, system: "You are a helpful assistant.", messages: [{ role: "user", content: "Hello!" }], stream: true, }); for await (const event of stream) { if (event.type === "content_block_delta") { process.stdout.write(event.delta.text); } } ``` ```curl curl https://api.example.com/v1/messages \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "hf:deepseek-ai/DeepSeek-V3-0324", "max_tokens": 100, "system": "You are a helpful assistant.", "messages": [{"role": "user", "content": "Hello!"}], "stream": true }' ``` -------------------------------- ### Streaming Completion (Python) Source: https://dev.synthetic.new/docs/openai/completions Shows how to enable and process streaming responses from the completions endpoint using Python. This allows for receiving tokens as they are generated, providing a more interactive experience. ```Python completion = client.completions.create( model="hf:deepseek-ai/DeepSeek-V3-0324", prompt="Once upon a time", max_tokens=50, stream=True ) for chunk in completion: if chunk.choices[0].text: print(chunk.choices[0].text, end='', flush=True) ``` -------------------------------- ### POST /openai/v1/completions Source: https://dev.synthetic.new/docs/openai/completions Creates a text completion for a given prompt and parameters using specified models. Supports various parameters to control the generation process, including sampling, stopping criteria, and streaming. ```APIDOC ## POST /openai/v1/completions ### Description Creates a completion for a provided prompt and parameters. ### Method POST ### Endpoint https://api.synthetic.new/openai/v1/completions ### Parameters #### Request Body - **model** (string) - Required - Model name (must be prefixed with `hf:`). See supported Models. - **prompt** (string/array) - Required - Text prompt(s) to generate completions for. Can be a string, array of strings, array of numbers, or array of arrays of numbers. - **echo** (boolean) - Optional - Echo back the prompt in addition to completion - **frequency_penalty** (number) - Optional - Penalty for token frequency (-2.0 to 2.0). Reduces repetition. - **logit_bias** (object) - Optional - Modify token likelihood. Maps token IDs to bias values (-100 to 100). - **logprobs** (number) - Optional - Include log probabilities on most likely tokens - **max_completion_tokens** (number) - Optional - Maximum tokens for completion - **max_tokens** (number) - Optional - Maximum number of tokens to generate - **min_p** (number) - Optional - Minimum probability for nucleus sampling - **n** (number) - Optional - Number of completions to generate (default: 1) - **presence_penalty** (number) - Optional - Penalty for token presence (-2.0 to 2.0). Encourages new topics. - **reasoning_effort** (string) - Optional - Control reasoning effort for thinking models: `low`, `medium`, or `high` - **stop** (string/array) - Optional - Stop sequence(s) - **stream** (boolean) - Optional - Stream response using server-sent events - **stream_options** (object) - Optional - Options for streaming (when `stream: true`) - **temperature** (number) - Optional - Sampling randomness (0.0-2.0). Higher = more random. - **top_k** (number) - Optional - Limit sampling to top K tokens - **top_p** (number) - Optional - Nucleus sampling threshold (0.0-1.0) - **user** (string) - Optional - Unique identifier representing your end-user ### Request Example ```json { "model": "hf:deepseek-ai/DeepSeek-V3-0324", "prompt": "The future of artificial intelligence is", "max_tokens": 50, "temperature": 0.7, "stop": ["\n"] } ``` ### Response #### Success Response (200) - **id** (string) - Unique identifier for the completion. - **object** (string) - Type of object, e.g., `text_completion`. - **created** (integer) - Unix timestamp of creation. - **model** (string) - The model used for completion. - **choices** (array) - An array of completion choices. - **index** (integer) - Index of the choice. - **text** (string) - The generated completion text. - **logprobs** (null) - Placeholder for log probabilities. - **finish_reason** (string) - Reason for finishing (e.g., `length`, `stop`). - **usage** (object) - Token usage statistics. - **prompt_tokens** (integer) - Tokens in the prompt. - **total_tokens** (integer) - Total tokens used. - **completion_tokens** (integer) - Tokens in the completion. #### Response Example ```json { "id": "49fb0537-dafc-441c-ad42-b4c4aa2f5193", "object": "text_completion", "created": 1757645512, "model": "accounts/fireworks/models/deepseek-v3-0324", "choices": [ { "index": 0, "text": " undeniably bright and holds the potential to revolutionize every aspect of our lives. As we stand on the cusp of technological advancements, AI is poised to become more sophisticated, integrated, and ethical. From transforming industries to enhancing daily conveniences, AI\'", "logprobs": null, "finish_reason": "length" } ], "usage": { "prompt_tokens": 7, "total_tokens": 57, "completion_tokens": 50 } } ``` ### Multiple Prompts Sending multiple prompts in a single request is supported. ### Streaming When `stream: true` is set, the response will be a series of Server-Sent Events. #### Streaming Response Example ``` data: {"id":"cmpl-abc123","object":"text_completion","created":1757644754,"model":"accounts/fireworks/models/deepseek-v3-0324","choices":[{"text":" in","index":0,"finish_reason":null}]} data: {"id":"cmpl-abc123","object":"text_completion","created":1757644754,"model":"accounts/fireworks/models/deepseek-v3-0324","choices":[{"text":" a","index":0,"finish_reason":null}]} data: {"id":"cmpl-abc123","object":"text_completion","created":1757644754,"model":"accounts/fireworks/models/deepseek-v3-0324","choices":[{"text":" far","index":0,"finish_reason":"length"}],"usage":{"prompt_tokens":5,"total_tokens":55,"completion_tokens":50}]} data: [DONE] ``` ``` -------------------------------- ### List Models - Python Source: https://dev.synthetic.new/docs/openai/models This Python code snippet demonstrates how to list all available models using the Synthetic API. It requires the 'openai' library and your API key and base URL. ```python import openai client = openai.OpenAI( api_key="SYNTHETIC_API_KEY", base_url="https://api.synthetic.new/openai/v1" ) # List all available models models = client.models.list() print(models) ``` -------------------------------- ### GET /v2/quotas Source: https://dev.synthetic.new/docs/synthetic/quotas Retrieve information about your API usage quotas and limits. This request does not count against your subscription limits. ```APIDOC ## GET /v2/quotas ### Description Retrieve information about your API usage quotas and limits. ##### Tip **/quotas** requests do not count against your subscription limits! ##### The Synthetic API is still under development. If there is more data you would like to see and access, please let us know! ### Method GET ### Endpoint https://api.synthetic.new/v2/quotas ### Parameters #### Query Parameters None #### Request Body None ### Request Example ```python import requests headers = { "Authorization": "Bearer SYNTHETIC_API_KEY" } response = requests.get( "https://api.synthetic.new/v2/quotas", headers=headers ) print(response.json()) ``` ### Response #### Success Response (200) - **subscription** (object) - Information about the subscription limits. - **limit** (integer) - The total limit for the subscription. - **requests** (integer) - The number of requests made. - **renewsAt** (string) - The date and time when the subscription renews. #### Response Example ```json { "subscription": { "limit": 135, "requests": 0, "renewsAt": "2025-09-21T14:36:14.288Z" } } ``` ### Helpful Alias You can add this alias to your `~/.bashrc` or `~/.zshrc` to quickly get your quota information via `synthetic_quota`. ```bash alias synthetic_quota='curl -s https://api.synthetic.new/v2/quotas \ -H "Authorization: Bearer ${SYNTHETIC_API_KEY}" \ | jq --color-output .' ``` ``` -------------------------------- ### Multiple Prompts Completion (Python) Source: https://dev.synthetic.new/docs/openai/completions Demonstrates sending multiple prompts in a single request to the completions endpoint using Python. This can be more efficient for generating completions for several distinct inputs. ```Python completion = client.completions.create( model="hf:deepseek-ai/DeepSeek-V3-0324", prompt=[ "The capital of France is", "The largest planet in our solar system is" ], max_tokens=10 ) ``` -------------------------------- ### Send and Receive Messages (Python) Source: https://dev.synthetic.new/docs/anthropic/messages Demonstrates how to send and receive messages using the Anthropic API via the Synthetic platform. Requires the 'anthropic' Python library and an API key. It sends a user message and prints the assistant's text response. ```Python import anthropic client = anthropic.Anthropic( api_key="SYNTHETIC_API_KEY", base_url="https://api.synthetic.new/anthropic/v1" ) response = client.messages.create( model="hf:deepseek-ai/DeepSeek-V3-0324", max_tokens=100, messages=[ {"role": "user", "content": "What is the capital of France?"} ] ) print(response.content[0].text) ``` -------------------------------- ### Count Tokens API Response - JSON Source: https://dev.synthetic.new/docs/anthropic/messages/count-tokens Example JSON response from the Synthetic API's /messages/count_tokens endpoint, showing the estimated number of input tokens. ```json { "input_tokens": 20 } ``` -------------------------------- ### Create Text Completion (Python) Source: https://dev.synthetic.new/docs/openai/completions Generates a text completion using the Synthetic API's OpenAI-compatible endpoint. Requires an API key and base URL. Supports various parameters for controlling the generation process. ```Python import openai client = openai.OpenAI( api_key="SYNTHETIC_API_KEY", base_url="https://api.synthetic.new/openai/v1" ) completion = client.completions.create( model="hf:deepseek-ai/DeepSeek-V3-0324", prompt="The future of artificial intelligence is", max_tokens=50, temperature=0.7, stop=["\n"] ) print(completion.choices[0].text) ``` -------------------------------- ### Get Quotas - Bash Alias Source: https://dev.synthetic.new/docs/synthetic/quotas A helpful bash alias to quickly retrieve quota information using cURL and jq. This alias, 'synthetic_quota', simplifies the process of checking your API usage limits. ```bash alias synthetic_quota='curl -s https://api.synthetic.new/v2/quotas \ -H "Authorization: Bearer ${SYNTHETIC_API_KEY}" \ | jq --color-output .' ``` -------------------------------- ### Streaming Completion (TypeScript) Source: https://dev.synthetic.new/docs/openai/completions Demonstrates how to enable and process streaming responses from the completions endpoint using TypeScript. This allows for receiving tokens as they are generated, providing a more interactive experience. ```TypeScript const stream = await client.completions.create({ model: "hf:deepseek-ai/DeepSeek-V3-0324", prompt: "Once upon a time", maxTokens: 50, stream: true }); for await (const chunk of stream) { if (chunk.choices[0]?.text) { process.stdout.write(chunk.choices[0].text); } } ``` -------------------------------- ### List Models - TypeScript Source: https://dev.synthetic.new/docs/openai/models This TypeScript code snippet demonstrates how to list all available models using the Synthetic API. It requires the 'openai' library and your API key and base URL. ```typescript import OpenAI from 'openai'; const client = new OpenAI({ apiKey: 'SYNTHETIC_API_KEY', baseURL: 'https://api.synthetic.new/openai/v1' }); async function listModels() { const models = await client.models.list(); console.log(models); } listModels(); ``` -------------------------------- ### Synthetic API Search Response (JSON) Source: https://dev.synthetic.new/docs/synthetic/search This is an example of the JSON response structure returned by the Synthetic API's search endpoint. It contains a list of search results, each with a URL, title, text snippet, and publication date. ```json { "results": [{ "url": "https://curl.se/docs/projdocs.html", "title": "curl — Project Documentation", "text": "...", "published": "2025-11-05T00:00:00.000Z" }] } ``` -------------------------------- ### Multiple Prompts Completion (TypeScript) Source: https://dev.synthetic.new/docs/openai/completions Demonstrates sending multiple prompts in a single request to the completions endpoint using TypeScript. This can be more efficient for generating completions for several distinct inputs. ```TypeScript const completion = await client.completions.create({ model: "hf:deepseek-ai/DeepSeek-V3-0324", prompt: [ "The capital of France is", "The largest planet in our solar system is" ], maxTokens: 10 }); ``` -------------------------------- ### Get Chat Completion Response (JSON) Source: https://dev.synthetic.new/docs/openai/chat-completions This snippet shows a typical JSON response from a chat completion API. It includes metadata like ID, creation timestamp, model used, and the generated content. The content itself is a string that may contain markdown. ```json { "id": "296a8fcb-181d-46d4-ad9b-b380befa9a07", "object": "chat.completion", "created": 1757644754, "model": "accounts/fireworks/models/deepseek-v3-0324", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "The capital of France is **Paris**. \n\nParis is known for its rich history, iconic landmarks like the Eiffel Tower and the Louvre Museum, and its cultural significance as a global hub for art, fashion, and cuisine. \n\nLet me know if you'd like more details!" }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 16, "total_tokens": 74, "completion_tokens": 58 } } ``` -------------------------------- ### List Models - Curl Source: https://dev.synthetic.new/docs/openai/models This curl command shows how to list all available models using the Synthetic API. It requires your API key for authentication. ```bash curl -X GET "https://api.synthetic.new/openai/v1/models" \ -H "Authorization: Bearer SYNTHETIC_API_KEY" ``` -------------------------------- ### POST /openai/v1/chat/completions Source: https://dev.synthetic.new/docs/openai/chat-completions Creates a model response for a given chat conversation. Supports various parameters for controlling generation, sampling, and tool usage. ```APIDOC ## POST /openai/v1/chat/completions ### Description Creates a model response for a given chat conversation. Supports various parameters for controlling generation, sampling, and tool usage. ### Method POST ### Endpoint https://api.synthetic.new/openai/v1/chat/completions ### Parameters #### Request Body - **messages** (array) - Required - List of messages comprising the conversation - **model** (string) - Required - Model name (must be prefixed with `hf:`). See supported Models. - **frequency_penalty** (number) - Optional - Penalty for token frequency (-2.0 to 2.0). Reduces repetition. - **logit_bias** (object) - Optional - Modify token likelihood. Maps token IDs to bias values (-100 to 100). - **logprobs** (boolean/number) - Optional - Return log probabilities of output tokens - **max_completion_tokens** (number) - Optional - Maximum tokens for completion (including reasoning tokens) - **max_tokens** (number) - Optional - Maximum number of tokens to generate - **min_p** (number) - Optional - Minimum probability for nucleus sampling - **n** (number) - Optional - Number of completion choices to generate (default: 1) - **parallel_tool_calls** (boolean) - Optional - Enable parallel function calling during tool use - **presence_penalty** (number) - Optional - Penalty for token presence (-2.0 to 2.0). Encourages new topics. - **reasoning_effort** (string) - Optional - Control reasoning effort for thinking models: `low`, `medium`, or `high` - **response_format** (object) - Optional - Specify output format (JSON schema, JSON object, etc.) - **seed** (number) - Optional - Random seed for deterministic sampling - **stop** (string/array) - Optional - Stop sequence(s) - **stream** (boolean) - Optional - Stream response using server-sent events - **stream_options** (object) - Optional - Options for streaming (when `stream: true`) - **temperature** (number) - Optional - Sampling randomness (0.0-2.0). Higher = more random. - **tool_choice** (string/object) - Optional - Control tool calling: `auto`, `none`, or specific tool - **tools** (array) - Optional - List of tools the model may call - **top_k** (number) - Optional - Limit sampling to top K tokens - **top_logprobs** (number) - Optional - Number of top token probabilities to return - **top_p** (number) - Optional - Nucleus sampling threshold (0.0-1.0) - **user** (string) - Optional - Unique identifier representing your end-user - **function_call** (string/object) - Optional - (Deprecated) Control function calling: `auto`, `none`, or specific function - **functions** (array) - Optional - (Deprecated) List of functions the model may call ### Message Object - **role** (string) - Required - Role: `system`, `user`, `assistant`, `tool`, or `function` - **content** (string/array) - Required - Message content (text string or array of content parts) - **name** (string) - Optional - Name of the participant (for user/system messages) - **tool_calls** (array) - Optional - Tool calls to be executed (for assistant messages) - **tool_call_id** (string) - Optional - ID of the tool call (for tool messages) - **reasoning_content** (string) - Optional - Reasoning content for thinking models (for assistant messages) - **function_call** (object) - Optional - (Deprecated) Function call to be executed (for assistant messages) ### Uploading images for vision models For multimodal image input, you can send images in your message's `content` array as follows: ```json { "role": "user", "content": [ { "type": "image_url", "image_url": { "url": "https://synthetic.new/images/totoro.jpg" } } ] } ``` Image URLs can either be real URLs to files available over the internet, or base64-encoded strings containing the image data in the standard format: ``` data:;base64, ``` For example: ``` data:image/png;base64,iVBOR... ``` We support the following image formats: `image/jpeg`, `image/png`, `image/gif`, `image/webp`, `image/tiff`. ### Request Example ```python import openai client = openai.OpenAI( api_key="SYNTHETIC_API_KEY", base_url="https://api.synthetic.new/openai/v1" ) completion = client.chat.completions.create( model="hf:deepseek-ai/DeepSeek-V3-0324", messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is the capital of France?"} ], max_tokens=100, temperature=0.7 ) print(completion.choices[0].message.content) ``` ``` -------------------------------- ### Create Embeddings (Python) Source: https://dev.synthetic.new/docs/openai/embeddings This Python code snippet demonstrates how to create embeddings for a single text input using the Synthetic API. It initializes the OpenAI client with the API key and base URL, then calls the embeddings.create method with the specified model and input text. The resulting embedding's dimensions are printed. ```python import openai client = openai.OpenAI( api_key="SYNTHETIC_API_KEY", base_url="https://api.synthetic.new/openai/v1" ) response = client.embeddings.create( model="hf:nomic-ai/nomic-embed-text-v1.5", input="The quick brown fox jumps over the lazy dog." ) embedding = response.data[0].embedding print(f"Embedding dimensions: {len(embedding)}") ``` -------------------------------- ### Create Convenient 'synclaude' Bash Function Source: https://dev.synthetic.new/docs/guides/claude-code Defines a bash function named 'synclaude' that sets up all necessary environment variables for using Claude Code with Synthetic and then executes the 'claude' command. This simplifies launching Claude Code with the desired configuration. ```bash # Add to ~/.bashrc or ~/.zshrc synclaude() { ANTHROPIC_BASE_URL=https://api.synthetic.new/anthropic \ ANTHROPIC_AUTH_TOKEN=${SYNTHETIC_API_KEY} \ ANTHROPIC_DEFAULT_OPUS_MODEL=hf:zai-org/GLM-4.6 \ ANTHROPIC_DEFAULT_SONNET_MODEL=hf:zai-org/GLM-4.6 \ ANTHROPIC_DEFAULT_HAIKU_MODEL=hf:zai-org/GLM-4.6 \ CLAUDE_CODE_SUBAGENT_MODEL=hf:zai-org/GLM-4.6 \ CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 \ claude "$@" } # Then use: synclaude ``` -------------------------------- ### Create Text Completion (TypeScript) Source: https://dev.synthetic.new/docs/openai/completions Generates a text completion using the Synthetic API's OpenAI-compatible endpoint in TypeScript. Requires an API key and base URL. Supports various parameters for controlling the generation process. ```TypeScript import OpenAI from 'openai'; const client = new OpenAI({ apiKey: "SYNTHETIC_API_KEY", baseURL: "https://api.synthetic.new/openai/v1" }); async function main() { const completion = await client.completions.create({ model: "hf:deepseek-ai/DeepSeek-V3-0324", prompt: "The future of artificial intelligence is", maxTokens: 50, temperature: 0.7, stop: ["\n"] }); console.log(completion.choices[0].text); } main(); ``` -------------------------------- ### Configure Claude Code Environment Variables Source: https://dev.synthetic.new/docs/guides/claude-code Sets environment variables in bash to configure Claude Code to use Synthetic's Anthropic API. This includes server URL, authentication token, default models for different plans, and privacy settings. ```bash # Server configuration export ANTHROPIC_BASE_URL=https://api.synthetic.new/anthropic # What server to talk to instead of the default export ANTHROPIC_AUTH_TOKEN=${SYNTHETIC_API_KEY} # Auth key # Model configuration export ANTHROPIC_DEFAULT_OPUS_MODEL=hf:zai-org/GLM-4.6 # The model to use for opus plan mode export ANTHROPIC_DEFAULT_SONNET_MODEL=hf:zai-org/GLM-4.6 # The model to use for most tasks export ANTHROPIC_DEFAULT_HAIKU_MODEL=hf:zai-org/GLM-4.6 # Primarily used for summarization export CLAUDE_CODE_SUBAGENT_MODEL=hf:zai-org/GLM-4.6 # When starting subagents, what model to use # Privacy configuration export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 # Don't send telemetry data ``` -------------------------------- ### Synthetic API Search Request (Python) Source: https://dev.synthetic.new/docs/synthetic/search This Python code demonstrates how to perform a search using the Synthetic API. It utilizes the 'requests' library to send a POST request with the necessary authorization header and search query. ```python import requests headers = { "Authorization": "Bearer SYNTHETIC_API_KEY" } response = requests.post( "https://api.synthetic.new/v2/search", headers=headers, data={ "query": "docs for the python requests library" } ) print(response.json()) ``` -------------------------------- ### Create Text Completion (curl) Source: https://dev.synthetic.new/docs/openai/completions Creates a text completion using the Synthetic API via a curl command. This demonstrates making a POST request to the completions endpoint with necessary headers and a JSON payload. ```bash curl -X POST https://api.synthetic.new/openai/v1/completions \ -H "Authorization: Bearer SYNTHETIC_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "hf:deepseek-ai/DeepSeek-V3-0324", "prompt": "The future of artificial intelligence is", "max_tokens": 50, "temperature": 0.7, "stop": ["\n"] }' ``` -------------------------------- ### Handle Streaming Chat Completions (Python) Source: https://dev.synthetic.new/docs/openai/chat-completions This Python code demonstrates how to handle streaming responses from the chat completions API. It iterates over chunks of data as they are received and prints the content incrementally. This is useful for real-time applications. ```python completion = client.chat.completions.create( model="hf:deepseek-ai/DeepSeek-V3-0324", messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Tell me a short story."} ], max_tokens=100, stream=True ) for chunk in completion: if chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end='', flush=True) ```