To facilitate integration and usage, the operator API of LAS is designed to be as compatible as possible with the OpenAI API. By modifying a few configurations such as base url, model, and api_key, you can easily integrate ModelArk model services into your existing system.
tip
Community third-party SDKs are not maintained by the Volcano Engine team. This document is for reference only.
Before calling the operator, you need to generate an API Key for operator invocation. It is recommended to configure the API Key as an environment variable for more secure operator calls. For details, see API key management.
pip install --upgrade "openai>=1.0"
from openai import OpenAI import os client = OpenAI( # The base URL for model invocation base_url="https://operator.las.ap-southeast-1.volces.com/api/v1", # Replace with your API Key api_key=os.environ.get("ARK_API_KEY"), ) completion = client.chat.completions.create( # Replace with Model ID model="doubao-seed-1-6-251015", messages = [ {"role": "user", "content": "Hello"}, ], ) print(completion.choices[0].message.content)
To pass fields not supported by the OpenAI SDK, use the extra_body dictionary, such as the thinking field to toggle deep thinking for the model.
from openai import OpenAI import os client = OpenAI( # The base URL for model invocation base_url="https://operator.las.ap-southeast-1.volces.com/api/v1", # Replace with your API Key api_key=os.environ.get("ARK_API_KEY"), ) completion = client.chat.completions.create( # Replace with Model ID model="doubao-seed-1-6-251015", messages = [ {"role": "user", "content": "Hello"}, ], extra_body={ "thinking": { "type": "disabled", # Deep thinking capability not enabled # "type": "enabled", # Deep thinking capability enabled } } ) print(completion.choices[0].message.content)
This can be used to pass extra information, such as configuring an ID to link logs or enabling data encryption capabilities.
from openai import OpenAI import os client = OpenAI( # The base URL for model invocation base_url="https://operator.las.ap-southeast-1.volces.com/api/v1", # Replace with your API Key api_key=os.environ.get("ARK_API_KEY"), ) completion = client.chat.completions.create( # Replace with Model ID model="doubao-seed-1-6-251015", messages = [ {"role": "user", "content": "Hello"}, ], # Custom request id extra_headers={"X-Client-Request-Id": "202406251728190000B7EA7A9648AC08D9"} ) print(completion.choices[0].message.content)
Install LangChain OpenAI SDK:
pip install langchain-openai
from langchain_openai import ChatOpenAI from langchain_core.prompts import PromptTemplate import os llm = ChatOpenAI( # Replace with your API Key openai_api_key=os.environ.get("ARK_API_KEY"), # The base URL for model invocation openai_api_base="https://operator.las.ap-southeast-1.volces.com/api/v1", # Replace with Model ID model="doubao-seed-1-6-251015", ) template = """Question: {question} Answer: Let's think step by step.""" prompt = PromptTemplate.from_template(template) question = "What NFL team won the Super Bowl in the year Justin Beiber was born?" llm_chain = prompt | llm print(llm_chain.invoke(question))